有什么方法可以轻松地在 Java Applet 中显示非常大的图像(使用较少的部分)?
我需要在 Java Applet 上显示大图像而不增加默认堆空间的功能。使用 ImageIO.read() 将大图像读取到 BufferedImage 时出现“内存不足”异常(预期会发生什么)。
为了解决这个问题,首先想到的就是将大图像分成更小的部分。
我的问题是:
是否有人对实现此功能的方向有一些提示(包括在滚动图像时显示正确的部分)? Java 有内置的东西来支持这个吗?有什么例子吗?
I need the functionality to show large images on a Java Applet without increasing the default heap space. I'm getting the "Out of memory" exception when reading the large image using ImageIO.read() into a BufferedImage (what was expected to happen).
To solve this issue, the first thing that comes to mind is to divide the large image into lesser parts.
My question is:
Does anyone have some tips on which direction to take to implement this functionality (which includes showing the correct part when scrolling the image)? Does Java have anything built-in to support this? Any examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用零件。最简单的方法是让服务器提供商提供较小的图块,您可以根据需要请求。
如果没有,您必须在小程序中自行完成。加载图像 - 将其分割为图块,并使每个图块将自身重新编码为字节流,例如 jpeg。将渲染的图块附加为软引用,以便尽可能晚地对其进行垃圾收集。如果渲染的图块已被 gc'ed,则解码 jpeg 字节流。
如果您有很多,甚至可以考虑将切片序列化到本地存储。
You must work with parts. The simplest is to have the server provider smallish tiles you Can request As needed.
If not you must dó it yourself in the applet. Load the image - split it in tiles and have each tile reencode itself to a bytestream e.g as jpeg. Attach the rendered tile as a soft reference so it Will be garbage collected as late as possible. If the rendered tile has been gc'ed then decode the jpeg bytestream.
If you have a LOT then even consider serializong tiles to local storage.