Java添加水印文字


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM