其他分享
首页 > 其他分享> > IO水印文字效果

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);
 } }

标签:java,BufferedImage,水印,height,width,文字效果,IO,new,import
来源: https://www.cnblogs.com/wangqianbao/p/13088796.html