java之io给图添加水印ImageIO

Posted 今进

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java之io给图添加水印ImageIO相关的知识,希望对你有一定的参考价值。

 

对一个图像实现生成缩略图

package j09;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Imasl {

public static void main(String[] args) throws IOException {
BufferedImage i=ImageIO.read( new File("D:\g.jpg"));
int w=150;
int h=200;

BufferedImage g=new BufferedImage(w,h,BufferedImage.TYPE_INT_BGR);
Graphics m=g.getGraphics();

m.drawImage(i, 0, 0, w, h,12,12, i.getWidth(), i.getHeight(), null);
m.dispose();
ImageIO.write(g,"jpg",new File("D://kd21.jpg"));

BufferedImage is=ImageIO.read( new File("D://kd21.jpg"));


BufferedImage gs=new BufferedImage(500,500,BufferedImage.TYPE_INT_BGR);
Graphics md=gs.getGraphics();

md.drawImage(is, 0, 0, 500, 500, null);
md.dispose();
ImageIO.write(gs,"jpg",new File("D://d212.jpg"));

}

}

 对一个图像实现水银图标效果

package j09;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
//图形水印
public class Imats {

public static void main(String[] args) throws IOException {
BufferedImage i=ImageIO.read( new File("D:\g.jpg"));
BufferedImage l=ImageIO.read( new File("D:\loge.png"));
Graphics m=i.getGraphics();

m.drawImage(l, i.getWidth()-100, 0, l.getWidth(), l.getHeight(), null);
m.dispose();
ImageIO.write(i,"jpg",new File("D://d21.jpg"));

}

 

}

 裁剪图像的某部生成新图像

package j09;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class Caijian {
//原始截图
public static void main(String[] args) throws IOException {
File fiel=new File("D://g.jpg");
BufferedImage i=ImageIO.read(fiel);
BufferedImage g=new BufferedImage(250,250,BufferedImage.TYPE_INT_RGB);
Graphics s=g.getGraphics();
s.drawImage(i, 0,0,250, 250,250, 590,250+250, 590+250, null);//前四个数确定目标窗口大小,后四个数确定截图位置
s.dispose();
ImageIO.write(g, "jpg", new File("D://dsa.jpg"));
}

}

以上是关于java之io给图添加水印ImageIO的主要内容,如果未能解决你的问题,请参考以下文章

java给图片添加图片水印,设置样式平铺,拉伸

Thumbnails为图片加水印

Java 给图片加 文字水印

如何运用Java 给图片加文字水印?

图片压缩,裁切,水印工具类

iOS--给图片添加水印