package com;
//添加水印文字
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Random;

public class Imgword {
    public static void main(String[] args) throws IOException {
        BufferedImage im =ImageIO.read(new FileInputStream("d:/img/111.jpg"));
        int iw = im.getWidth();
        int ih = im.getHeight();
        Graphics g = im.getGraphics();
        Color color = new Color(255,0,255,100); //设置随机颜色
        g.setColor(color);
        //g.setColor(Color.BLUE);
        Font font = new Font("宋体",Font.PLAIN,30);  //设置字体
        g.setFont(font);
        String str = "12345";
        //int x = iw/2;
        //int y = ih/2;
        Random ran = new Random();  // 随机位置
        int x = ran.nextInt(iw);
        int y = ran.nextInt(ih);
        g.drawString(str,x,y);
        g.dispose();
        ImageIO.write(im,"jpg",new File("d:/img/111.jpg"));
    }
}

 

相关文章:

  • 2021-12-15
  • 2019-07-12
  • 2021-12-04
  • 2021-11-21
  • 2021-09-07
  • 2021-12-15
  • 2021-11-12
  • 2021-12-14
猜你喜欢
  • 2021-08-06
  • 2021-12-15
  • 2021-11-11
  • 2021-12-15
  • 2022-01-01
  • 2021-10-07
  • 2021-10-17
相关资源
相似解决方案