使用Java和AsyncScalr缩放大图像 [英] Scale large images using Java and AsyncScalr

查看:148
本文介绍了使用Java和AsyncScalr缩放大图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Servlet中使用AsyncScalr来缩小一些大图像(~10-15 MegaBytes),实际的大小调整过程大约需要40ms,这并不多。过度杀伤来自将本地存储中的图像作为BufferedImage读取。
因此时间大多如下:

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 :

读取图像文件:1630ms !!
调整图像大小:41ms
写图像:40ms

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回答我的问题加载图像已经解决了这个问题。

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

这篇关于使用Java和AsyncScalr缩放大图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆