在 J2ME 中加载图像?
我对 J2ME 上的概念并不陌生,但我有点懒惰,但我不应该这样做: 最近,我的应用程序一直将图像加载到内存中,因为它们是糖果......
Sprite example = new Sprite(Image.createImage("/images/example.png"), w, h);
我不太确定这是最好的方法,但它在我的摩托罗拉 Z6 上运行良好,直到昨晚,当我在旧三星中测试该应用程序时手机和图像甚至无法加载,需要多次尝试启动线程才能显示。 屏幕保持白色,所以我意识到这一定是关于图像加载的问题,我做得不太好......有谁可以告诉我如何在我的应用程序中正确地创建加载例程?
I'm not so new to the concepts present on J2ME, but I'm sort of lazy in ways I shouldn't:
Lately my app has been loading images into memory as they were candy...
Sprite example = new Sprite(Image.createImage("/images/example.png"), w, h);
and I'm not really sure it's the best way, but it worked fine in my Motorola Z6, until last night, when I tested the app in a old Samsung cellphone and the images wont even load and require several attemps of starting the thread to show up. The screen was left on white, so I realized that it has to be something about Image loading that I'm not doing quite well... Is there anyone who can tell me how to properly make a loading routine in my app?.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定您到底在寻找什么,但您描述的行为听起来很像您正在经历 OutOfMemory 异常。 尝试减小图像的尺寸(堆使用情况基于尺寸)并查看该行为是否停止。 这会让您知道这是否确实是内存不足问题或其他问题。
其他提示:
I'm not sure exactly what you are looking for, but the behavior you describe very much sounds like you are experiencing an OutOfMemory exception. Try reducing the dimensions of your images (heap usage is based on dimension) and see if the behavior ceases. This will let you know if it is truly an OutOfMemory issue or something else.
Other tips:
使用电影图像(在一个图像中按定义尺寸排列的一组图像)并使用逻辑一次将它们拉出来。
因为它们组合成一个图像,所以您可以节省每个图像的标头空间,从而减少使用的内存。
该技术首先用于 MIDP 1.0 内存受限设备。
Using a film image(a set of images by a defined dimension in one image) and use logic to pull them out one at a time.
Because they a grouped into one image, you are saving header space per image and thus can reduce the memory used.
This techniques was first used in MIDP 1.0 memory constrained devices.
使用 Fostah 不反复加载图像的方法,我创建了以下类:
因此,每当我需要图像时,我首先向池请求它,或者只是将其加载到池中。
Using the Fostah approach of not loading images over and over, I made the following class:
So, whenever I need an image I first ask the pool for it, or just load it into the pool.