Java Picture plus watermark

Source: Internet
Author: User

Code

Import Java.awt.font;import java.awt.graphics;import Java.awt.image;import Java.awt.image.bufferedimage;import Java.io.file;import Java.io.fileoutputstream;import Com.sun.image.codec.jpeg.jpegcodec;import Com.sun.image.codec.jpeg.jpegimageencoder;import Javax.imageio.imageio;public class WaterMark{public static void Pressimage (String dst,string src,int x,int y) {try{file f=new File (src); Image img=imageio.read (f); int W=img.getwidth ( NULL); int h=img.getheight (NULL); BufferedImage bimg=new BufferedImage (W, H, Bufferedimage.type_int_rgb); Graphics g=bimg.getgraphics (); G.drawimage (img, 0, 0, W, h, NULL); File F1=new file (DST), Image Img1=imageio.read (F1), int w1=img1.getwidth (NULL), int h1=img1.getheight (NULL); G.drawimage (IMG1, W-w1-x, h-h1-y, W1, H1, NULL); G.dispose (); FileOutputStream out=new FileOutputStream (DST); JPEGImageEncoder Encoder=jpegcodec.createjpegencoder (out); Encoder.encode (bimg); Out.close ();} catch (Exception e) {e.printstacktrace ();}} public static void Presstext (String presstext, String Targetimg,string fontname,int fontstyle,int color,int fontsize,int x,int y) {try{file f=new File (TARGETIMG); Image img= Imageio.read (f); int w=img.getwidth (null); int h=img.getheight (NULL); BufferedImage bimg=new BufferedImage (W,H,BUFFEREDIMAGE.TYPE_INT_RGB); Graphics g=bimg.getgraphics (); G.drawimage (img, 0, 0, W, h, null); G.setfont (new Font (fontname,fontstyle,fontsize)); g.DrawString (Presstext, W-fontsize-x, h-fontsize/2-y); G.dispose (); FileOutputStream out=new FileOutputStream (targetimg); JPEGImageEncoder Encoder=jpegcodec.createjpegencoder (out); Encoder.encode (bimg); Out.close ();} catch (Exception e) {e.printstacktrace ();}} public static void Main (string[] args) {pressimage ("1.jpg", "2.jpg", 200,200);p resstext ("Really good Miss You", "3.jpg", "Arial", font.bold,0,20,200,200);}}


Java Picture plus watermark

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.