简体   繁体   中英

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);

回答我的问题,使用java.awt.Toolkit加载图像已解决了该问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM