iOS 编程/内存建议

发布于 2024-11-24 12:13:13 字数 396 浏览 0 评论 0原文

这很难解释,但希望我能很好地阐明我的问题。

我正在开发一个具有多个级别的 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 技术交流群。

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

发布评论

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

评论(1

泛泛之交 2024-12-01 12:13:13

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.

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