public void ImageResize(String srcImage,String result,int desWidth, int desHeight) {
try {
BufferedImage src = ImageIO.read(new File(srcImage)); // 读入文件
// 获取指定长宽的图像实例
Image image = src.getScaledInstance(desHeight, desWidth, Image.SCALE_DEFAULT);
// 缩放图像
BufferedImage tag = new BufferedImage(desHeight, desWidth, BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
// 绘制缩小后的图
g.drawImage(image, 0, 0, null);
g.dispose();
ImageIO.write(tag, "jpg", new File(result));// 输出到文件流
}
catch (IOException e) {
e.printStackTrace();
}
}
public image getscaledinstance ( int width, int height, int hints )
创建此图像的缩放版本。返回一个新的 image 对象,默认情况下,该对象按指定的 width 和 height 呈现图像。即使已经完全加载了初始源图像,新的 image 对象也可以被异步加载。