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",