|
@@ -81,7 +81,9 @@ public class AddWatermarkUtil {
|
|
|
sb.append(tempChar);
|
|
|
}
|
|
|
// 通过设置后两个输入参数给水印定位
|
|
|
- g.drawString(sb.toString(), 20, srcImgHeight - (contentLength - j - 1) * tempY - 50);
|
|
|
+ //右下角
|
|
|
+ g.drawString(sb.toString(), srcImgWidth - maxLength, srcImgHeight - (contentLength - j - 1) * tempY - 50);
|
|
|
+ // g.drawString(sb.toString(), 20, srcImgHeight - (contentLength - j - 1) * tempY - 50);
|
|
|
}
|
|
|
g.dispose();
|
|
|
|
|
@@ -118,15 +120,15 @@ public class AddWatermarkUtil {
|
|
|
* @param text
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public static void addWaterMark(File inputFile, File outputFile, String text) throws IOException {
|
|
|
+ public static void addWaterMark(File inputFile, File outputFile, Color markContentColor, int fontSize, String text) throws IOException {
|
|
|
Image image = ImageIO.read(inputFile);
|
|
|
int imgWidth = image.getWidth(null);// 获取图片的宽
|
|
|
int imgHeight = image.getHeight(null);// 获取图片的高
|
|
|
|
|
|
int angel = 315;// 旋转角度
|
|
|
- int xpadding = 40;// 每个水印水平间隔
|
|
|
- int ypadding = 40;// 每个水印垂直间隔
|
|
|
- int fontSize = 10;
|
|
|
+ int xpadding = 280;// 每个水印水平间隔
|
|
|
+ int ypadding = 280;// 每个水印垂直间隔
|
|
|
+ // int fontSize = 10;
|
|
|
|
|
|
BufferedImage bi = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
|
@@ -150,11 +152,11 @@ public class AddWatermarkUtil {
|
|
|
int stringWidth = g.getFontMetrics(g.getFont()).charsWidth(text.toCharArray(), 0, text.length());
|
|
|
|
|
|
// 旋转水印
|
|
|
- // g.rotate(Math.toRadians(angel), (double) imgWidth / 2, (double) imgHeight / 2);
|
|
|
+ g.rotate(Math.toRadians(angel), (double) imgWidth / 2, (double) imgHeight / 2);
|
|
|
// 水印透明度
|
|
|
- // g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
|
|
|
+ g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
|
|
|
// 字体色
|
|
|
- g.setColor(Color.RED);
|
|
|
+ g.setColor(markContentColor);
|
|
|
|
|
|
int x = -imgHeight / 2;
|
|
|
int y = -imgWidth / 2;
|