给图片添加水印这个功能以前做项目的时候遇到过 但是后来好久不用今天突然想起来 就随笔记录一下吧 随便在记录一下自己当初踩的坑
package Img;
import java.awt.Color;
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 ImgUtil {
/**
* 添加图片水印
* @param pressImg
* @param targetImg
* @param x
* @param y
*/
public final static void pressImage(String pressImg, String targetImg,
int x, int y) {
try {
File _file = new File(targetImg);
Image src = ImageIO.read(_file);
int wideth = src.getWidth(null);
int height = src.getHeight(null);