ImageIO读取一张图片改变大小


package com.demo;

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

import javax.imageio.ImageIO;

/**
* @Description 读取一张图片改变大小
* @author FuJianyong
* 2015-1-20上午10:48:49
*/
public class ImageIORead {
/**
* 改变图片的大小
* @return boolean
*/
public static boolean readImage() {
//设定要生成的新图片的宽高和图片格式
BufferedImage newbi = new BufferedImage(500, 500, BufferedImage.TYPE_INT_BGR);
boolean val = false;
try {
//从硬盘读取一张图片
BufferedImage oldbi = ImageIO.read(new File("E:/DEMO/dd.jpg"));
//把读过的来的图片画到设定好的新图片上
newbi.getGraphics().drawImage(oldbi, 0, 0, 500, 500, null);
//通过ImageIO写到硬盘上去
val = ImageIO.write(newbi, "png", new File("E:/DEMO/ddd.png"));
return val;
}catch(IOException e) {
e.printStackTrace();
}
return val;
}
public static void main(String[] args) {
System.out.println(readImage());
}
}

你可能感兴趣的:(java)