标签: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"));
}
}
标签:graph rgb phi getwidth 图像 observer ack buffer rgs
原文地址:https://www.cnblogs.com/jinjinqiao/p/13095392.html