JAVA ÔÚͼÏñ´¦ÀíÖеÄÓ¦ÓÃ
ÏàÐÅ´ó¼ÒƽʱÅöµ½¹ýһЩÔÚJAVAÖжÔͼÏñ½øÐд¦ÀíµÄÐèÇ󣬱ÈÈçÐèÒª¶ÔÉÏ´«µÄͼƬ¼ÓÉÏ×Ô¼ºµÄÇ©Ãû»òͼ±ê£¬»òÕßÉú³ÉºÍ½âÎö¶¯Ì¬µÄGIFͼƬ£¬ÒÔ¼°´¦ÀíPSDÎļþͼÏñÐÅÏ¢¡£±¾ÎľÍJAVAÔÚͼÏñ´¦ÀíÖÐһЩ»ù±¾Ó¦ÓýøÐÐÁ˽éÉÜ¡£Ï£Íûͨ¹ýÄܹ»¶Ô´ó¼ÒÔÚÒÔºóµÄͼÏñ´¦ÀíÖÐÓÐЩ°ïÖú¡£
Ò»¡¢¶ÔÒ»¸öÏÖÓеÄͼƬ½øÐÐÎÄ×ÖºÍͼ±êµÄºÏ³É
ÎÒÃÇÏÈ´ÓÏÂÃæµÄÕâ¶Î¼òµ¥µÄ´úÂ뿪ʼ
import java.awt.*;
import javax.imageio.ImageIO;
import java.awt.image.*;
import java.io.*;
import com.sun.image.codec.jpeg.*;
/**
* @author Anders.Hu
* 2005-01-12
*/
public class Test {
public static void main(String[] args) {
try {
//¶ÁÈ¡Ä£°åͼƬÄÚÈÝ
BufferedImage image = ImageIO.read(new FileInputStream("c:\\1.jpg"));
Graphics2D g = image.createGraphics();//µÃµ½Í¼ÐÎÉÏÏÂÎÄ
g.setColor(Color.BLACK); //ÉèÖû±ÊÑÕÉ«
//ÉèÖÃ×ÖÌå
g.setFont(new Font("ËÎÌå", Font.LAYOUT_LEFT_TO_RIGHT, 15));//дÈëÇ©Ãû
g.drawString("ºÜºÃ³ÔÚÀ£¬Òª²»ÒªÒ²À´Ò»¿Ú£¿",43, image.getHeight() - 10);
g.dispose();
FileOutputStream out = new FileOutputStream("c:\\2.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
ÏàÐÅ´ó¼Ò¿´µ½ÕâÀïÒѾ֪µÀÁË´óÖµIJÙ×÷¹ý³Ì£¬ÎÒÏëÎÒ»¹ÊÇÔÚÕâÀï°Ñ»ù±¾µÄÔÀí¼òµ¥ËµÃ÷һϱãÓÚ¶ÔºóÐøÄÚÈݵIJûÊö£ºÊ×ÏÈÎÒÃÇͨ¹ýjavax.imageio.ImageIOµÄread·½·¨¶ÁȡͼÏñÔÚBufferedImageÖУ¬È»ºóÎÒÃÇ¿ÉÒÔͨ¹ýBufferedImageµÄcreateGraphics·½·¨È¡µÃͼÏñµÄÉÏÏÂÎıãÓÚ¶ÔͼÏñµÄ´¦Àí£¬Èç¼ÓÉÏ×Ô¼ºÏ²°®µÄÎÄ×Ö»òͼƬµÈ£¬×îºóµ÷ÓÃJPEGCodecµÄencode·½·¨½øÐÐJPEG±àÂë,È»ºó¾ÍÊDZ£´æµ½ÎļþÖÐÁË¡£
ÐèÒªÌá³öµÄÊÇJPEGCodecÊǷDZê×¼À࣬Èç¹û³ÌÐòÊÇÔËÐÐJDK1.4ÒÔÉÏ°æ±¾µÄ»°,¿ÉÒÔ²ÉÈ¡ÒÔÏ´úÂë½øÐÐJPEG±àÂë:
ImageIO.write(image, "JPEG", out);
&n
Ïà¹ØÎĵµ£º
¶¨Òå°´Öµ´«µÝºÍ°´ÒýÓô«µÝÕâÁ½¸öÊõÓïÊÇÖØÒªµÄ¡£
°´Öµ´«µÝÒâζ×ŵ±½«Ò»¸ö²ÎÊý´«µÝ¸øÒ»¸öº¯Êýʱ£¬º¯Êý½ÓÊÕµÄÊDzÎÊýµÄÒ»¸ö¸±±¾¡£Òò´Ë£¬Èç ¹ûº¯ÊýÐÞ¸ÄÁ˸òÎÊý£¬½ö¸Ä±ä¸±±¾£¬¶øÔʼֵ±£³Ö²»±ä¡£°´ÒýÓô«µÝÒâζ×ŵ±½«Ò»¸ö²ÎÊý´«µÝ¸øÒ»¸öº¯Êýʱ£¬º¯Êý½ÓÊÕµÄÊDzÎÊýµÄÄÚ´æµØÖ·£¬¶ø²»ÊDzÎÊýµÄ¸±±¾¡£Òò ´Ë£¬Èç¹ûº¯ÊýÐÞ¸ÄÁ˸òÎÊý£¬µ÷ ......
²åÈëÅÅÐòµÄ¹¤×÷ÔÀíÊÇͨ¹ý¹¹½¨ÓÐÐòÐòÁУ¬¶ÔÓÚδÅÅÐòÊý¾Ý£¬ÔÚÒÑÅÅÐòÐòÁÐÖдӺóÏòǰɨÃ裬ÕÒµ½ÏàӦλÖò¢²åÈë¡£Æä¾ßÌå²½Öè²Î¼û´úÂë¼°×¢ÊÍ¡£
view plaincopy to clipboardprint?
/**
* ²åÈëÅÅÐò<br/>
* <ul>
* <li>´ÓµÚÒ»¸öÔªËØ¿ªÊ¼£¬¸ÃÔªËØ¿ÉÒÔÈÏΪÒѾ±»ÅÅÐò ......
1£®ÈçºÎѧϰ³ÌÐòÉè¼Æ£¿
JAVAÊÇÒ»ÖÖƽ̨£¬Ò²ÊÇÒ»ÖÖ³ÌÐòÉè¼ÆÓïÑÔ£¬ÈçºÎѧºÃ³ÌÐòÉè¼Æ²»½ö½öÊÊÓÃÓÚJAVA£¬¶ÔC++µÈÆäËû³ÌÐòÉè¼ÆÓïÑÔÒ²Ò»Ñù¹ÜÓá£Óбà³Ì¸ßÊÖÈÏ
Ϊ£¬JAVAÒ²ºÃCÒ²ºÃûʲô·Ö±ð£¬ÄÃÀ´¾ÍÓá£ÎªÊ²Ã´ËûÃÇÄÜ´ïµ½Èç´Ë¾³½ç£¿ÎÒÏëÊÇÒòΪ±à³ÌÓïÑÔÖ®¼äÓй²Í¨Ö®´¦£¬Áì»áÁ˱à³ÌµÄ¾«Ë裬×ÔÈ»Äܹ»×öµ½Ò»Í¨°Ùͨ¡£
鍼 ......
1¡¢ ¶ÔÏóµÄ³õʼ»¯
(1) ·Ç¾²Ì¬¶ÔÏóµÄ³õʼ»¯
ÔÚ´´½¨¶ÔÏóʱ£¬¶ÔÏóËùÔÚÀàµÄËùÓÐÊý¾Ý³ÉÔ±»áÊ×ÏȽøÐгõʼ»¯¡£
»ù±¾ÀàÐÍ£ºintÐÍ£¬³õʼ»¯Îª0¡£
Èç¹ûΪ¶ÔÏó£ºÕâЩ¶ÔÏó»á°´Ë³Ðò³õʼ»¯¡£
¡ùÔÚËùÓÐÀà³ÉÔ±³õʼ»¯Íê³ÉÖ®ºó£¬²Åµ÷Óñ¾ÀàµÄ¹¹Ôì·½·¨´´½¨¶ÔÏó¡£
¹¹Ôì·½·¨µÄ×÷ÓþÍÊdzõʼ»¯ ......