Code
1import java.awt.Color;
2import java.awt.Font;
3import java.awt.Graphics;
4import java.awt.Image;
5import java.awt.image.BufferedImage;
6import java.io.File;
7import java.io.FileOutputStream;
8import javax.imageio.ImageIO;
9import com.sun.image.codec.jpeg.JPEGCodec;
10import com.sun.image.codec.jpeg.JPEGImageEncoder;
11{/codecitation}
12{codecitation class="brush: java; gutter: true;"}
13
14pressText("www.ceapet.com",fileName,"Arial",14,12);
15
16{/codecitation}
17{codecitation class="brush: java; gutter: true;"}
18public static void pressText(String pressText, String targetImg,String fontName, int fontStyle, int fontSize)
19{
20try {
21File _file = new File(targetImg);
22Image src = ImageIO.read(_file);
23int width = src.getWidth(null);
24int height = src.getHeight(null);
25BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
26Graphics g = image.createGraphics();
27g.drawImage(src, 0, 0, width, height, null);
28//String s="www.ceapet.com";
29g.setColor(Color.BLACK);
30g.setFont(new Font(fontName, fontStyle, fontSize));
31g.drawString(pressText, width - 100, height - 1);
32g.dispose();
33FileOutputStream out = new FileOutputStream(targetImg);
34JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
35encoder.encode(image);
36out.close();
37}catch (Exception ex){ex.printStackTrace();}
38}
1import java.awt.Color;
2import java.awt.Font;
3import java.awt.Graphics;
4import java.awt.Image;
5import java.awt.image.BufferedImage;
6import java.io.File;
7import java.io.FileOutputStream;
8import javax.imageio.ImageIO;
9import com.sun.image.codec.jpeg.JPEGCodec;
10import com.sun.image.codec.jpeg.JPEGImageEncoder;
11{/codecitation}
12{codecitation class="brush: java; gutter: true;"}
13
14pressText("www.ceapet.com",fileName,"Arial",14,12);
15
16{/codecitation}
17{codecitation class="brush: java; gutter: true;"}
18public static void pressText(String pressText, String targetImg,String fontName, int fontStyle, int fontSize)
19{
20try {
21File _file = new File(targetImg);
22Image src = ImageIO.read(_file);
23int width = src.getWidth(null);
24int height = src.getHeight(null);
25BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
26Graphics g = image.createGraphics();
27g.drawImage(src, 0, 0, width, height, null);
28//String s="www.ceapet.com";
29g.setColor(Color.BLACK);
30g.setFont(new Font(fontName, fontStyle, fontSize));
31g.drawString(pressText, width - 100, height - 1);
32g.dispose();
33FileOutputStream out = new FileOutputStream(targetImg);
34JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
35encoder.encode(image);
36out.close();
37}catch (Exception ex){ex.printStackTrace();}
38}