哪位大神能给一个java的快速高效的图片缩放的功能
我自己也写了一个方法,但是速度不是很快,而且批量操作的时候耗时太长。求做过的大神们给个提示
public static BufferedImage createThumbnail(BufferedImage image, int size, String type) {
BufferedImage thumbnail = null;
if(image == null) {
System.out.println("文件不存在");
return thumbnail;
}
if(size <= 0) {
return thumbnail;
}
Image srcUpload = null;
try {
srcUpload = (Image)image;
int newWidth = 0, newHight = 0;
int w = srcUpload.getWidth(null);
int h = srcUpload.getHeight(null);
if("width".equals(type)) {
newWidth = size;
newHight = (int) (h * size / w);
}
else if("hight".equals(type)) {
newHight = size;
newWidth = (int) (w * size / h);
}
thumbnail = new BufferedImage(newWidth, newHight, BufferedImage.TYPE_3BYTE_BGR);
thumbnail.getGraphics().drawImage(srcUpload.getScaledInstance(newWidth, newHight, Image.SCALE_SMOOTH), 0, 0, null);
}
catch(Exception e) {
e.printStackTrace();
}
return thumbnail;
}
------解决方案--------------------www.jmagick.org/? 这个不错,速度和效果都挺好,缺点是要安装imagemagick.
------解决方案--------------------
/**
* Resize an image
* @param originalImage The image file
* @param to The destination file
* @param w The new width (or -1 to proportionally resize)
&