Search code examples
javaimage-processingscaleimagingjai

Java Advanced Imaging Scaling Image


I have a very large image (~200,000x200,000 pixels) in the form of a RenderedImage. I cropped it and then scaled it using JAI's ScaleDescriptor (which returns a RenderedOp). My final image is only about 30x30 but when I call getAsBufferedImage (I get the PlanarImage first) from the resulting scaled image, it takes several minutes to create. I'm guessing there is some reference back to the original image which is taking such a long time, but I'm not sure. Does anyone know why this would take so long?

thanks, Jeff


Solution

  • With JAI you are building a rendering chain; so when you call .scale it does not actually scale at that point but just adds that to the chain (so in the debugger it will be instant). Only at the end when you go to realize the pixels in your new image does the operation happen.

    The amount of scaling you are doing seems like a lot and is may be very expensive. I have not done JAI in a few years; can you specify the scaling algorithm? It might be doing unnecessary interpolation when you can get away with something much simpler.