gpt4 book ai didi

iphone - UIImage + NSCache 与 [UIImage imageNamed :]

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:08:18 25 4
gpt4 key购买 nike

我有一个性能问题,如果我使用 [UIImage imageWithContentsOfFile: ] 从磁盘加载 JPG(是的,我不能在应用程序中提供任何 PNG 文件格式)图像,存储全局 NSCache 中的 UIImage 并使用 [UITableViewCell drawRect: ] 中的缓存图像。这种方法比用户 [UIImage imagedNamed:] 慢得多。

如果使用 Instruments“Time Profile”分析了性能,正如您在第一张图片中看到的那样,JPEG 始终在 [DBArtistTableViewCell drawRect:] 中解码。在第二张带有[UIImage imageNamed:] 解决方案的图片中,JPG 将不会解压缩。

NSCache + UIImage 解决方案: NSCache + UIImage

[UIImage imageNamed] 解决方案 UIImage imageNamed

简短的问题是:为什么 UIImage + NSCache 解决方案比 [UIImage imageNamed:] 解决方案慢,有什么魔力使用 [UIImage imageNamed:] 方法(是的,我知道缓存,但其余的魔法是什么)?

感谢您的帮助。

最佳答案

我相信原因是 UIImage imageNamed 导致数据被解压缩并存储在它的缓存中,而 UIImage imageWithContentsOfFile 加载压缩数据,但不解压缩直到您需要显示它为止。

关于iphone - UIImage + NSCache 与 [UIImage imageNamed :],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9326957/

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