使用可拉伸 UIImage 时获得最佳性能
我需要在我的应用程序中的多个 UIImageView 中使用可拉伸的 UIImage 数百次。是否可以全局重用相同的可拉伸 UIImage,而不必每次需要将其添加到 UIImageView 时都在内存中重新创建它们?
我知道 [UIImage imageNamed:] 缓存图像以获得更好的性能,但这不能用于可拉伸图像!
谢谢,
迈克
I need to use a stretchable UIImage hundreds of times in my app in multiple UIImageViews. Is it okay to globally reuse the same stretchable UIImage instead of having to recreate them in memory each time I need to add it to a UIImageView?
I know [UIImage imageNamed:] caches images for better performance, but this cannot be used for stretchable images!
Thanks,
Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哦,当然,您应该始终将图像存储一次,然后每次要绘制时都调用同一图像。通常,对于具有大量图像的项目,我有一个 SpriteManager 类,其中包含一个充满精灵的 NSDictionary。然后我可以通过文件名引用每一个。这样每个图像只加载一次,速度明显更快。
不过,绝对最有效的方法就是使用 OpenGL ES。如果您已经绘制了数百张图像,我绝对建议您这样做。
Oh, absolutely, you should always store your image once and then call that same image every time you want to draw it. Typically for projects with a lot of images I have a single SpriteManager class that contains an NSDictionary full of sprites. Then I can reference each one via filename. This way each image is loaded only once, which is significantly faster.
The absolutely most efficient way to do this, though, is just to use OpenGL ES. And if you've got hundreds of images being drawn, I absolutely recommend that you do so.
绝对:重复使用你的图像。您是否将其存储在全局变量中?确保您
保留
图像(或将其放入某些全局类(如您的应用程序)的保留属性中),因为它可能是自动释放的。Definitely: Reuse your image. Are you storing it in a global variable? Make sure you
retain
the image (or put it in a retained property fo some global class like your Application) since it probably came AutoReleased.