javaimageimage-processingimage-scalingimgscalr

Scale large images using Java and AsyncScalr


I'm using AsyncScalr in a Servlet to scale down some large images (~ 10-15 MegaBytes), the actual resizing process takes about 40ms which is not much. The overkill comes from Reading the Image from Local Storage as a BufferedImage. so the times are mostly like :

read the image file : 1630ms !! resizing the image : 41ms writing the image : 40ms

below is the code that I'm using, is there any more optimal way to do this?

        final FileImageInputStream fileImageInputStream = new FileImageInputStream(file);
        BufferedImage bufferedImage = ImageIO.read(fileImageInputStream);

        // resize file
        Future<BufferedImage> result = AsyncScalr.resize(bufferedImage, Method.SPEED, width, OP_ANTIALIAS, OP_BRIGHTER);
        try {
            bufferedImage = result.get();
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }
        catch (ExecutionException e) {
            e.printStackTrace();
        }

        // Write the image
        ImageIO.write(bufferedImage, imageOutput, outputStream);

Solution

  • to answer my question, using java.awt.Toolkit to load images has solved the problem.