UIImage Cache图像吗? [英] Does the UIImage Cache image?
问题描述
UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"xx.jpg"]
UIImage *img = [UIImage imageNamed:@"xx.jpg"]
在第二种类型中图像会被缓存吗?
而在第一种类型中键入图像不会被缓存?
In the second type will the image get cached ?
Whereas the in the first type the images doesn't get cached?
推荐答案
-
-initWithContentsOfFile:
创建一个没有缓存的新图像,这是一种普通的初始化方法。The
-initWithContentsOfFile:
creates a new image without caching, it's an ordinary initialization method.+ imageNamed:
方法使用缓存。以下是来自 UIImage Reference :The
+imageNamed:
method uses cache. Here's a documentation from UIImage Reference:
此方法在系统缓存中查找具有指定名称的图像对象,并返回该对象(如果存在)。如果匹配的图像对象不在缓存中,则此方法从指定的文件加载图像数据,缓存它,然后返回结果对象。
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.
UIImage将保留加载的图像,使其保持活动状态直到低内存条件将导致缓存被清除。
UIImage will retain loaded image, keeping it alive until low memory condition will cause the cache to be purged.
更新Swift:
在Swift中,UIImage(名称为...)
函数是一个缓存图像。Update for Swift: In Swift the
UIImage(named: "...")
function is the one that caches the image.这篇关于UIImage Cache图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!