java_图片添加水印
public static String markImgMark(String sourceImg, String targetImg,String jwd,Integer types) throws IOException {
String result = "添加图片水印出错";
File file = new File(sourceImg);
Image img = ImageIO.read(file);
int width = img.getWidth(null);
int height = img.getHeight(null);
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(img.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null);
String type = "";
Font font = new Font("Serif", Font.BOLD, 30);
g.fillRect(0, 0, 100, 0);
g.setPaint(Color.red);
g.setFont(font);
FontRenderContext context = g.getFontRenderContext();
Rectangle2D bounds = font.getStringBounds(s, context);
double x = (width - bounds.getWidth()) / 2;
double y = (height - bounds.getHeight()) / 2;
double ascent = -bounds.getY();
double baseY = y + ascent;
String s = "经纬度: "+jwd;
String sj = "时间:" +DateUtils.getTime();
g.drawString(s, (int) 20, (int) 80);
g.drawString(sj, (int) 20, (int)130);
g.drawString(type, (int) 20, (int)180);
File sf = new File(targetImg);
ImageIO.write(bi, "jpg", sf);
System.out.println("添加图片水印成功"+DateUtils.getTime());
return result;
}