iphone存储图像的最佳方式 [英] iphone best way to store images

查看:140
本文介绍了iphone存储图像的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,需要从网络缓存一些图像,图像可能是100x100

I'm developing an app that needs to cache some images from the web the images are likely to be 100x100

我只需要知道哪个更好:

I just need to know which is better:


  1. 将图像存储为iPhone文件系统中的文件

  2. 将它们作为blob存储在sqlite Db中以及已保存在数据库中的其他数据。

感谢您的帮助。

推荐答案

Apple绝对不推荐在数据库中存储图像,文件系统实际上非常擅长在磁盘上定位文件(本例中的图像),这使其成为最佳解决方案保存图像。这些是苹果技术传播者在巴黎iPhone技术讲座世界巡回赛中使用的完全相同的词语。如果它只是几张图片,你可能会侥幸逃脱,但是当这个数字可能变得非常大时,文件就可以了。

Storing images in the database is definitely not recommended by Apple, the filesystem is actually really good at locating files (images in this case) on the disk, which makes it the best solution for saving images. These were the exact same words an Apple technology evangelist used in the iPhone Tech Talk World Tour in Paris. If it are only a few images, you might get away with it, but when the number can potentially become quite large, files is the way to go.

此外,你可以使用延迟加载方法来获取磁盘的图像,这将延迟将图像从磁盘加载到真正需要的时候。

Besides, you can use the lazy loading methods to grab the images of the disk, this will delay loading the image from disk to when it really is needed.

[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image.png"]]

编辑:imageWithContentsOfFile不会立即加载图像,因此不会锁定线程,也不会缓存图像。另一种方法imageNamed:确实锁定线程并立即加载图像,在光明的一面,它会缓存图像。

imageWithContentsOfFile does not load the image at once, thus not locking the thread, neither does it cache the image. The other method imageNamed: does lock the thread and loads the image at once, on the bright side, it does cache the image.

这篇关于iphone存储图像的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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