Package com.my.utils;
Import Java.awt.AlphaComposite;
Import Java.awt.Color;
Import Java.awt.Font;
Import Java.awt.Graphics2D;
Import Java.awt.Image;
Import java.awt.RenderingHints;
Import Java.awt.image.BufferedImage;
Import Java.io.File;
Import java.io.IOException;
Import Javax.imageio.ImageIO; public class ByteArray {public static void main (string[] args) {file Srcfile=new file ("C:/users/administrator/des
ktop/working folder/Picture/screenshot_2015-09-16-13-55-06.png ");
File Pathfile=new file ("c:/users/administrator/desktop/working folder/Picture/fukejibing.png"); Addtextforimg (Srcfile, "This is the test of the text", 50,50,1, "F:/QQQQ."
JPEG ");
Addimgforimage (Srcfile, Pathfile, MB, 0.5f, "f:/wwww.jpeg"); /** * * @param file target picture * @param text added @param positionx x axis * @param positiony y axis * @param alpha Text Transparency * @param path shows the location of the picture (for example: f:/qqqq.jpeg)/public static void Addtextforimg (File file,string text,int positionx,i NT Positiony,float Alpha, String path) {try {Image SrciMG = imageio.read (file); BufferedImage buffimg = new BufferedImage (Srcimg.getwidth (null), srcimg.getheight (null), Buffere
DIMAGE.TYPE_INT_RGB);
int wideth = Srcimg.getwidth (null);
int height = srcimg.getheight (null);
Graphics2D g = buffimg.creategraphics ();
G.setrenderinghint (renderinghints.key_text_antialiasing, renderinghints.value_text_antialias_on);
G.drawimage (srcimg, 0, 0, wideth, height, null);
G.setcolor (New Color (89,87,87));
G.setfont (New Font ("founder Orchid Pavilion in Black _gbk", font.bold,54));
G.setcomposite (Alphacomposite.getinstance (Alphacomposite.src_atop,alpha));
g.DrawString (text, Positionx, positiony);
g.DrawString (text, positionx*2, positiony*2);
G.dispose ();
Imageio.write (buffimg, "JPEG", new file (path));//output to file stream} catch (IOException e) {e.printstacktrace (); }/** * * * @param srcfile target picture * @param pathfile watermark Picture * @param positionx x Axis * @param positiony y axis * @pa
Ram Alpha Picture Transparency * @param path shows the location of the picture (for example: f:/www.jpeg)/public static void Addimgforimage (File srcfile,file pathfile,int positionx,in
T positiony,float alpha,string Path) {try {Image srcimg = Imageio.read (srcfile); BufferedImage buffimg = new BufferedImage (Srcimg.getwidth (null), srcimg.getheight (null), BufferedImage.
TYPE_INT_RGB);
int wideth = Srcimg.getwidth (null);
int height = srcimg.getheight (null);
Graphics2D g = buffimg.creategraphics ();
G.setrenderinghint (renderinghints.key_text_antialiasing, renderinghints.value_text_antialias_on);
G.drawimage (srcimg, 0, 0, wideth, height, null);
Image Src_biao = Imageio.read (pathfile);
int wideth_biao = Src_biao.getwidth (null);
int height_biao = Src_biao.getheight (null);
G.setcomposite (Alphacomposite.getinstance (Alphacomposite.src_atop,alpha));
G.drawimage (Src_biao, Positionx,positiony, Wideth_biao, Height_biao, NULL);
G.dispose (); Imageio.write (buffimg, "JPEG", new file (path));//output to file stream} catch (IOException e) {e.printstacktrace ();
}
}
}