//S1-获取文字水印的宽、高 int width1 = 30 * getTextLength("水印文字"); int height1 = 30; int widthDiff = width - width1; int heightDiff = height - height1; int x = 10; int y = 10; if (x > widthDiff) { x = widthDiff; } if (y > heightDiff) { y = heightDiff; } graphics2D.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.3F));//设置水印 graphics2D.drawString("水印文字", x, y + 30);//x:横坐标,y:纵坐标 graphics2D.dispose();
// 5、 创建图像编码工具类 Date date = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String string = sdf.format(date);