iOS 编程/内存建议
这很难解释,但希望我能很好地阐明我的问题。
我正在开发一个具有多个级别的 iOS 项目,每个级别将在屏幕上同时包含最多 40 个全屏图像,但每个图像的 98% 是透明的,它们一起创建一个图像。每张图片均为 640 X 960 PNG。我可以准确对齐这些的唯一方法是让它们全部具有完整的分辨率,因为我无法为每个设置位置。
加载应用程序时,图像很容易占用超过 130MB 的内存。当图像总共只需要 1-2mb 时,这似乎很疯狂。
显然,我需要将所有图像作为单独的 UIImageView 加载,因为应用程序需要随着时间的推移显示每个图像。即它们在加载时隐藏,并且在用户与屏幕交互时取消隐藏。
我的应用程序完全可以运行,但我想知道是否有人对我可以使用更少内存来执行此操作有一些想法。
我期待听到一些想法。
This is hard to explain but hopefully I can articulate my problem well enough.
I am working on a iOS project with several levels and each level will contain up to 40 full screen images on screen at any one time, but 98% of each image is transparent and together they create one image. Each image is 640 X 960 PNG. The only way I can align these accurately is to have them all the full res as I can't set a location for each one.
When the app is loaded the images can easily take up over 130mb of memory. This seems crazy when the image should really only take 1-2mb in total.
Obviously I need all images to be loaded as separate UIImageViews as the app needs to reveal each image over time. i.e. they are hidden when loaded and are unhidden as the user interacts with the screen.
I have the app fully operational but I am wondering if someone might have some ideas as to a way that I can do this that will use much less memory.
I look forward to hearing some ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
40 * ~2mb 非常接近 130mb。
要么提前计算最终图像,这样就不会同时存储它们,要么找到一种按需延迟加载它们的方法。还可以考虑使用平铺图形。
40 * ~2mb is pretty close to 130mb.
Either compute a final image ahead of time so that you're not storing them simultaneously, or find a way to lazy-load them on-demand. Also consider using tiled graphics.