I’m using the following code to load an scaled version of a big JPEG image. I’d like to know if there are better (faster) ways to do it. I’m developing a thumbnail explorer-type app and I’d like to create the thumbnails the fastest way possible.
Here is the code. As you can see, I’m not loading the full image and then rescaling it. I rescale it while loading. Also, I’d like to know if the result BufferedImage is hardware accelerated:
private static BufferedImage readSubsampling(File file, int maxSize) throws IOException {
Iterator readers = ImageIO.getImageReadersByFormatName("jpeg");
ImageReader reader = (ImageReader)readers.next();
ImageInputStream iis=null;
iis = ImageIO.createImageInputStream(file);
reader.setInput(iis, true, true);
ImageReadParam param = reader.getDefaultReadParam();
int size = Math.max(reader.getWidth(0), reader.getHeight(0));
int subsampling = size/maxSize + (size%maxSize != 0 ? 1 : 0);
param.setSourceProgressivePasses(0, 4);
param.setSourceSubsampling(subsampling, subsampling, 0, 0);
BufferedImage image = reader.read(0, param);
reader.dispose();
return image;
}
Thanks in advance