如何在 J2ME 中从大图像文件制作拇指?

发布于 2024-08-29 04:08:14 字数 167 浏览 2 评论 0原文

我正在尝试在 J2ME 应用程序中显示大图像文件。但我发现,当图像文件太大时,我什至无法创建 Image 实例并出现 OutOfMemory 异常。

我想我可以以小块的形式读取图像文件并创建缩略图以显示给用户?
有办法做到这一点吗?或者还有其他方法可以在应用程序中显示图像文件吗?
谢谢。

I'm trying to display a big image file in a J2ME application. But I found that when the image file is too big I can not even create the Image instance and get a OutOfMemory exception.

I suppose I can read the image file in small chunks and create a thumbnail to show to the user?
Is there a way to do this? Or is there any other method to display the image file in the application?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀手六號 2024-09-05 04:08:14

有很多事情可以尝试,具体取决于您想要做什么以及您希望应用程序在什么手机上运行。

如果您的图像打包在 MIDlet JAR 文件中,您对 MIDP 运行时的操作的控制就会较少,因为需要先解压缩数据,然后才能将其作为图像加载。在这种情况下,我建议简单地打包一个较小的图像。减少像素数量或用于编码每个像素的字节数。

如果您可以从基于 GCF 的输入流(文件、网络...)读取图像字节,您需要了解图像格式(BMP 很简单,JPEG 不太那么...),以便您可以将其缩小为可变的Image 对象会占用更少的内存,一次一大块。

在这种情况下,您还需要决定缩放算法应该是什么。如果手机上的 LCDUI 实现编写得不好,将文件中的 32 位像素转换为内存中的 8 位像素实际上可能无法按预期工作。

根据图像的内容,简单地删除一半的像素列和一半的像素行可能正是您所需要的,也可能是一种过于幼稚的方法。您可能想查看现有的图像缩放算法并将其写入您的应用程序中。

请记住,基本 LCDUI 可能不是在屏幕上显示图像的唯一方法。 JSR-184、JSR-239、JSR-226 和 eSWT 都可以让您以完全独立于手机 LCDUI 实现的方式执行此操作。

最后,让我们面对现实吧,如果您的手机 MIDP 运行时不允许您同时创建至少 2 个屏幕大小的全色深度图像,那么可能是时候决定不支持该特定手机了。

There are a number of things to try, depending on exactly what you are trying to do and what handset you want your application to run on.

If your image is packaged inside your MIDlet JAR file, You have less control over what the MIDP runtime does because the data needs to be unzipped before it can be loaded as an Image. In that case, I would suggest simply packaging a smaller image. Either reduce the number of pixels or the number of bytes used to encode each pixel.

If you can read the image bytes from a GCF-based InputStream (file, network...), You need to understand the image format (BMP is straightforward, JPEG less so...) so you can scale it down into a mutable Image object that would take less memory, one chunk at a time.

In that case, you also need to decide what your scaling algorithm should be. Turning 32 bits pixels in a file into 8 bits pixels in memory might not actually work as expected if the LCDUI implementation on your mobile phone was badly written.

Depending on the content of the image, simply removing half of the pixel columns and half of the pixel lines may be either exactly what you need or way too naive an approach. You may want to look at existing image scaling algorithms and write one into your application.

Remember that basic LCDUI may not be the only way to display an image on the screen. JSR-184, JSR-239, JSR-226 and eSWT could all allow you to do that in a way that may be totally independant from your handset LCDUI implementation.

Finally, let's face it, if your phone MIDP runtime doesn't allow you to create at least 2 images the size of your screen at full color depth at the same time, then it might be time to decide to not support that specific handset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文