Java更快地加载图像 [英] Java load images faster

查看:60
本文介绍了Java更快地加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Java编写一个简单的轻量级图像浏览器,目前我正在使用 ImageIO.read(new File(/* PATH_TO_IMAGE */))加载图像.

I'm trying to write a simple lightweight image browser in Java, currently I'm using ImageIO.read(new File(/* PATH_TO_IMAGE */)) to load the images.

问题是,加载10个JPEG需要10467毫秒.这似乎减慢了很多,尤其是当我计划加载数百张图像时.

Problem is, to load 10 JPEG's takes 10467 milliseconds. This seems much to slow especially when I'm planning on possibly loading hundreds of images.

有没有更快的加载方式?

Is there any faster way to load them?

此外,我通过覆盖JPanel中的 paintComponent 并使用Graphics2D绘制缩略图来绘制缩略图(如果有任何区别).(并随时提出一种更好的方法来做到这一点)

Also, I'm drawing thumbnails by overriding paintComponent in a JPanel and painting the thumbnails using Graphics2D, if that makes any difference. (and feel free to suggest a better way to do this)

推荐答案

如果要显示缩略图,则应考虑创建和存储缩略图.

If you want to display thumbnails, you should consider creating, and storing, thumbnails.

您不能期望每秒能够加载数百个6 MB的文件.缩略图约为50 KB,加载速度更快(其中加载"是从硬盘读取并在内存中解码).

You can't expect to be able to load hundreds of 6 MB files per second. Thumbnails are about 50 KB, and load a lot quicker (where 'load' is reading from the hard disk and decoding them in-memory).

这篇关于Java更快地加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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