首页 > 编程语言 > 详细

java 图形化小工具Abstract Window Toolit ImageIO缩放图片,添加水印

时间:2021-05-08 16:34:43      阅读:20      评论:0      收藏:0      [点我收藏+]

实现步骤:

读取图像
Image src = ImageIO.read
创建目标图像
BufferedImage distImage = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_RGB);
//目标图像画笔画图,把原图像画出来
Graphics2D graphics2D = (Graphics2D) distImage.getGraphics();
graphics2D.drawImage(src,0, 0, dstWidth, dstHeight, null);
//添加文字水印
graphics2D.setColor(Color.red);
graphics2D.drawString("V哥教育", 30, 30);
//保存到文件
ImageIO.write(distImage,"png", new File("C:\\Users\\ZHANGMINGDA\\Desktop\\日报\\订单详情-smal.png"));
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @ClassName ImageIOTest
 * @projectName: object1
 * @author: Zhangmingda
 * @description: XXX
 * date: 2021/5/8.
 */
public class ImageIOTest {
    public static void main(String[] args) throws IOException {
        //读取图像
        Image src = ImageIO.read(new File("C:\\Users\\ZHANGMINGDA\\Desktop\\日报\\订单详情.png"));
        //设置目的图像宽高
        int dstWidth = 500;
        int dstHeight = 200;
        //创建目的图像
        BufferedImage distImage = new BufferedImage(dstWidth, dstHeight, BufferedImage.TYPE_INT_RGB);
        //目标图像画笔画图,把原图像画出来
        Graphics2D graphics2D = (Graphics2D) distImage.getGraphics();
        graphics2D.drawImage(src,0, 0, dstWidth, dstHeight, null);
        //添加文字水印
        graphics2D.setColor(Color.red);
        graphics2D.drawString("V哥教育", 30, 30);
        //保存到文件
        ImageIO.write(distImage,"png", new File("C:\\Users\\ZHANGMINGDA\\Desktop\\日报\\订单详情-smal.png"));
    }
}

 

java 图形化小工具Abstract Window Toolit ImageIO缩放图片,添加水印

原文:https://www.cnblogs.com/zhangmingda/p/14744500.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!