Skip to content

Instantly share code, notes, and snippets.

@MangoLiu
Last active December 30, 2015 08:09
Show Gist options
  • Save MangoLiu/7801029 to your computer and use it in GitHub Desktop.
Save MangoLiu/7801029 to your computer and use it in GitHub Desktop.
resize image (将图片按照指定大小输出)
public static void resizeImage(String srcImgPath, String distImgPath,
int width, int height) throws IOException {
File srcFile = new File(srcImgPath);
Image srcImg = ImageIO.read(srcFile);
BufferedImage buffImg = null;
buffImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
buffImg.getGraphics().drawImage(
srcImg.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0,
0, null);
ImageIO.write(buffImg, "JPEG", new File(distImgPath));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment