/**
* 修改图片大小
*/
public static void resizeImage(String url,double width,double height) throws IOException {
BufferedImage prevImage = ImageIO.read(new FileInputStream(url));
//double width = prevImage.getWidth();
//double height = prevImage.getHeight();
//double percent = size/width;
int newWidth = (int)(width * 0.33);
int newHeight = (int)(height * 0.25);
BufferedImage image = new BufferedImage(newWidth, newHeight,BufferedImage.TYPE_INT_BGR);
Graphics graphics = image.createGraphics();
graphics.drawImage(prevImage, 0, 0, newWidth, newHeight, null);
OutputStream outImage=new FileOutputStream(url);
JPEGImageEncoder enc= JPEGCodec.createJPEGEncoder(outImage);
enc.encode(image);
outImage.close();
}
最近在整理一些资源工具,放在网站分享 http://tools.maqway.com
欢迎关注公众号:麻雀唯伊 , 不定时更新资源文章,生活优惠,或许有你想看的