【发布时间】:2011-08-09 09:31:12
【问题描述】:
我正在使用 imgscalr-lib-3.1 创建缩略图,以在我的 Galleria-classic 相册中使用。 它正在减小大小(我的意思是像 100 * 100 的像素),但不是千字节(像 10K、20K)。 这是我的代码:
public static void createThumbNails(String path) throws ImageFormatException, IOException{
File image ;
FileInputStream in = null ;
JPEGImageDecoder decoder;
BufferedImage bufferedImage ;
BufferedImage outBufferedImage ;
Scalr scalr = new Scalr();
File folder = new File(path+"/images/album/award/");
File[] files = folder.listFiles();
File outputfile ;
for(File file : files){
image = file;
in = new FileInputStream(file);
decoder = JPEGCodec.createJPEGDecoder(in);
bufferedImage = decoder.decodeAsBufferedImage();
outBufferedImage = scalr.resize(bufferedImage, Scalr.Method.SPEED,100);
ImageIO.write(outBufferedImage, "jpg", file);
}
in.close();
}
你们知道该怎么做吗? 谢谢。
【问题讨论】:
-
快速提示 Dave,imgscalr 使用所有静态方法,因此无需实例化它的实例——我应该将构造函数设为私有。对混乱感到抱歉。只需调用 Scalr.resize(...) 就是预期用途。
标签: java thumbnails resize scaletransform scalr