public void testImageZoom() {
try {
BufferedImage src = ImageIO.read(new File("d:\\tmp\\1.jpg")); // 读入文件
int width = src.getWidth(); // 得到源图宽
int height = src.getHeight(); // 得到源图长
// 获取一个宽、长是原来1/2的图像实例
Image image = src.getScaledInstance(width / 2, height / 2, Image.SCALE_DEFAULT);
BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); //缩放图像
Graphics g = tag.getGraphics();
g.drawImage(image, 0, 0, null); // 绘制缩小后的图
g.dispose();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageIO.write(tag,"JPEG",bos);// 输出到bos
FileOutputStream out = new FileOutputStream("d:\\tmp\\result.jpg");
out.write(bos.toByteArray()); //写文件
out.close();
} catch (IOException e) {
e.printStackTrace();
}