IO水印文字效果

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random; import javax.imageio.ImageIO; public class Meinv {  public static void main(String[] args) throws IOException {
  String src = "D:\\Demo\\op";
  String dst = "D:\\Demo\\op\\ting3";
  BufferedImage s = ImageIO.read(new File (src));
int width = s.getWidth();
int height = s.getHeight();
BufferedImage black = new BufferedImage(width, height,10);
black.getGraphics().drawImage(s, 0, 0, width, height,null ); BufferedImage i = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
Graphics g = i .getGraphics();
g.drawImage(black,0,0,width,height,null);
Random rand = new Random();
g.setColor(new Color(rand.nextInt(255),rand.nextInt(255),rand.nextInt(255)));
g.fillRect(0, 0, width, height);
g.setColor(new Color(255,255,255,120));
g.setFont(new Font("",Font.BOLD,40)); int x= width - 200;
int y = height -40;
g.drawString("王昭君",x,y);
 } }
上一篇:验证码的工具以及验证码的简单应用和小tips


下一篇:Java添加文字水印和图片水印