Java. imageIo add watermarks to images

Source: Internet
Author: User

Recently, I am working on a mall project. I want to add a watermark to the project images. ①. Add an image watermark. ②. Add a text watermark;

The following method is provided. We hope you can use it:

= "E:/2.png" =" e: \ logo.jpg "=" e:/3.jpg" ImageUtil. waterMarkImageByIcon (iconPath, srcImgPath, targerPath, 0, 00, 0.1f = ImageIO. read ("width:" + srcImg. getWidth ("height:" + srcImg. getHeight (= BufferedImage (srcImg. getWidth (Graphics2D g =), Image. SCALE_SMOOTH), 0, 0 (! =) BuffImg. getWidth ()/2) buffImg. getHeight ()/2 ImageIcon imgIcon = Image img = alpha = clarity; g. drawImage (img, width, height, = ImageIO. write (buffImg, "JPG" "watermark image added! "(! = InputStream is === ImageIO. read (= BufferedImage (srcImg. getWidth (Graphics2D g =), Image. SCALE_SMOOTH), 0, 0 (! =) BuffImg. getWidth ()/2) buffImg. getHeight ()/2g. setFont (Font ("", Font. BOLD, 30 alpha = ImageIO. write (buffImg, "JPG" "watermark text added! "(! = (! =

There is also an image scaling code:

           zoomImage(String srcPath, String destPath,  destHeight, = ImageIO.read( imgWidth = imgHeight = srcWidth = srcHeight = (srcHeight >== () Math.round(((destHeight * 1.0 / srcHeight) *= () Math.round(((destWidth * 1.0 / srcWidth) *= =0, 0/ 2) - (imgWidth / 2), (destHeight / 2) - (imgHeight / 2), "JPEG", 

 

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.