public static void setWaterMarkForIMGByFontString(String srcImgPath, String targerPath, Color markContentColor, String waterMarkContent){
OutputStream os = null;
try {
Image srcImg = ImageIO.read(new File(srcImgPath));
BufferedImage buffImg = new BufferedImage(srcImg.getWidth(null), srcImg.getHeight(null),
BufferedImage.TYPE_INT_RGB);
// 得到画笔对象
Graphics2D g = buffImg.createGraphics();
// 设置对线段的锯齿状边缘处理
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(srcImg.getScaledInstance(srcImg.getWidth(null), srcImg.getHeight(null), Image.SCALE_SMOOTH), 0,
0, null);
Font font = new Font("宋体", Font.PLAIN, 20);
g.setColor(markContentColor); // 根据图片的背景设置水印颜色
g.setFont(font);
int srcImgWidth = srcImg.getWidth(null);
int srcImgHeight = srcImg.getHeight(null);
int waterMarkLength = g.getFontMetrics(g.getFont()).charsWidth(waterMarkContent.toCharArray(), 0, waterMarkContent.length());
int x = srcImgWidth - waterMarkLength - 3;
int y = srcImgHeight - 3;
g.drawString(waterMarkContent, x, y);