开发者

iphone best way to store images

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. Store the images as files in the iPhone file system
  2. Store them as blob in a sqlite Db along wi开发者_JAVA技巧th other data already saved on the database.

Appreciate your help.


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"]]

Edit: 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.


From past experience, storing (and retrieving) images from the file system should be a bit faster than from the DB. As for ease of handling and maintenance it only depends on what you're more familiar with: SQL scripts or iphoneOS file system functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜