Hi,
An application I have reads in quite large images (jpegs) but only needs to work with smaller images so I subsample them with something like
ImageReadParam param = reader.getDefaultReadParam();
param.setSourceSubsampling(4, 4, 0, 0);
img = reader.read(0);
However, due to a bug in the jpeg reader that does not handle some meta data that I have fall back to other methods, one is using JAI to read the image and then resize (code is below, not I have to use reflection as some deployment environments don't have JAI available, I know I could design around this better but that's how it is).
try {
Class<?> c = ImageUtil.class.getClassLoader().loadClass("javax.media.jai.JAI");
if (c != null) {
URL url = new URL("file://" + file.getAbsolutePath());
Method m = c.getMethod("create", String.class, Object.class);
Object pi = m.invoke(null, "url", url);
img = (BufferedImage) pi.getClass().getMethod("getAsBufferedImage").invoke(pi);
}
} catch (Throwable tt) {
// ...
}
However some of the images are really large an now and again I get out of memory exceptions, is there anyway I can get JAI to subsample the image when it is read in the manner i read the images using an ImageReader?