保存用户照片和来自网络的照片

Saving user photos and photos from web

所以我遇到了这种情况。在应用程序阶段之一,我从他的照片库中获取所有用户照片。我得到它们 ALAsset's。我让他选择他想要的照片。然后我将他选择的照片保存到应用程序目录中,作为带有 HIGH_ 前缀的全尺寸照片和带有 LOW_ 前缀的照片缩略图。我需要这个,因为照片有一些属性,如时间等。我将这些属性保存到 SQL 数据库,其中照片名称字段以 HIGH_ 或 LOW_ 开头。当我需要获取照片时,我从数据库获取属性,然后执行 [UIImage imageWithContentsOfFile:photoPath]。谁能告诉我如何更有效地做到这一点,因为像这样编写和获取照片需要一些时间。在 iPhone 4 上,我有时甚至会收到内存警告。另一个问题是,我应该如何保存从网上获取的照片?

我的观点是正确的,Apple 写道,而不是使用核心数据,

It is better, however, if you are able to store BLOBs as resources on the filesystem, and to maintain links (such as URLs or paths) to those resources. You can then load a BLOB as and when necessary.

所以你做的是正确的,但也许你应该检查一下变形。如果收到警告,请确保从内存中删除不使用的图像

来自文档:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html 在“大数据对象 (BLOB)”部分下

另一种使用可变形的方法: Which way to store data(image)? NSData, String or Transformable

事实上,也许transformables至少是针对核心数据的: How should I store UIImages within my Core Data database?