从应用程序包加载图像的最佳方式 [英] Best way of loading images from application bundle

查看:93
本文介绍了从应用程序包加载图像的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从应用程序主程序包加载图像的最佳方法是什么。我正在使用

What is the best way of loading images from the application main bundle. I am using

[UIImage imageNamed: "image.png"];

但我听说这在内存使用和性能方面并不好。任何人都可以提供他/她的反馈吗?我的应用程序在发布时从主包中读取大量图像。我想让这个过程尽可能高效。

But I have heard that this is not good in terms of memory usage and performance. Can anyone please give his/her feedback on it? My application reads lots of images from main bundle at launch time. I want to make this process as efficient as possible.

最好的问候

推荐答案

如果你想尝试加载没有缓存的图像,你可以使用:

If you want to try loading the images without caching, you can use:

[[UIImage alloc] initWithContentsOfFile:@"image.png"]; 

首次加载图片可能会稍快一些,因为它不需要缓存它首先。如果您只需要使用一次这些图像,那么以这种方式尝试可能是有意义的。这样做的另一个好处是,您不会使用超长内存的图像缓存超过必要的时间。

This could be slightly faster loading the image for the first time, since it doesn't have to cache it first. If you only need to use these images once, it probably makes sense to try it this way. The other benefit of doing it this way is that you won't have an image cache using up memory for longer than necessary.

这篇关于从应用程序包加载图像的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆