Scale large images using Java and AsyncScalr

 ̄綄美尐妖づ 提交于 2019-12-10 10:42:41

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/12142069/scale-large-images-using-java-and-asyncscalr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!