/** * * @param filePath Original image Path * @param content Add watermark text/public static Boolean Photoaddwater (String FilePath,
String content) {//Get the original icon ImageIcon imageicon=new ImageIcon (FilePath);
Create Image Object Image Image=imageicon.getimage ();
int width=image.getwidth (NULL);
int height=image.getheight (NULL);
Create picture container BufferedImage bufferedimage=new bufferedimage (width, height, bufferedimage.type_int_rgb);
Create a painting Environment graphics2d g=bufferedimage.creategraphics ();
Text color G.setcolor (color.red);
Fonts font font=new font ("XXFarEastFont-Arial", Font.Bold, 50);
G.setfont (font);
G.drawimage (image, 0, 0,null);
g.DrawString (content, (WIDTH/15) *8, (HEIGHT/15) *14);
Change G.dispose ();
FileOutputStream Outputstream=null;
try {outputstream=new FileOutputStream ("f://test/" +system.currenttimemillis () + ". jpg");
JPEGImageEncoder encoder = Jpegcodec.createjpegencoder (OutputStream); JPEGEncodeParam param = ENcoder.getdefaultjpegencodeparam (BufferedImage);
Set 1 originals to save Param.setquality (1, true);
Encoder.encode (BufferedImage, param);
Outputstream.close ();
return true;
catch (FileNotFoundException e) {//TODO auto-generated catch block E.printstacktrace ();
catch (Imageformatexception e) {//TODO auto-generated catch block E.printstacktrace ();
catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();
}finally{try{if (OutputStream!=null) {outputstream.close ();
}catch (Exception e) {//Todo:handle Exception}} return false; }