Last active
December 30, 2015 08:09
-
-
Save MangoLiu/7801029 to your computer and use it in GitHub Desktop.
resize image (将图片按照指定大小输出)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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