gpt4 book ai didi

objective-c - UIImage 是否缓存图像?

转载 作者:IT王子 更新时间:2023-10-29 08:05:14 25 4
gpt4 key购买 nike

UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"xx.jpg"]
UIImage *img = [UIImage imageNamed:@"xx.jpg"]

在第二种类型中,图像会被缓存吗?
而在第一种类型中,图像不会被缓存?

最佳答案

  • -initWithContentsOfFile:创建一个没有缓存的新图片,这是一个普通的初始化方法。

  • +imageNamed: 方法使用缓存。这是来自 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 将保留加载的图像,使其保持事件状态,直到内存不足的情况导致缓存被清除。

Swift 更新:在 Swift 中,UIImage(named: "...") 函数用于缓存图像。

关于objective-c - UIImage 是否缓存图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8644455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com