码迷,mamicode.com
首页 > 编程语言 > 详细

java之io给图添加水印ImageIO

时间:2020-06-11 20:02:03      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:graph   rgb   phi   getwidth   图像   observer   ack   buffer   rgs   

 

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

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

标签:graph   rgb   phi   getwidth   图像   observer   ack   buffer   rgs   

原文地址:https://www.cnblogs.com/jinjinqiao/p/13095392.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!