简体   繁体   English

保存用户照片和网络照片

[英]Saving user photos and photos from web

So i have this situation with images. 所以我有这种情况的图像。 In one of app stages i get all user photos from his photo library. 在应用程序阶段之一中,我从他的照片库中获取所有用户照片。 I get them as ALAsset's . 我把它们当作ALAsset's I let him choose photo he wants. 我让他选择他想要的照片。 Then i save his chosen photo to applications directory as full size photo with HIGH_ prefix and a thumbnail of a photo with LOW_ prefix. 然后,我将他选择的照片作为带有HIGH_前缀的原尺寸照片和带有LOW_前缀的照片缩略图保存到应用程序目录中。 I need this because photos have some properties like time etc. I save those properties to SQL database with a field of photo name that begins with HIGH_ or LOW_. 我需要这样做是因为照片具有一些诸如时间等属性。我将这些属性保存到SQL数据库中,其照片名称字段以HIGH_或LOW_开头。 When i need to get photos i get properties from db and then do [UIImage imageWithContentsOfFile:photoPath] . 当我需要获取照片时,我从db获取属性,然后执行[UIImage imageWithContentsOfFile:photoPath] Can someone tell me how to do it more efficient because writing and getting photos like this takes some time. 有人可以告诉我如何提高效率,因为这样写和获取照片需要一些时间。 And on iPhone 4 i sometimes even get memory warnings. 在iPhone 4上,我有时甚至会收到内存警告。 AND another question would be, how should i save photos fetched from web? 另一个问题是,我应该如何保存从网上获取的照片?

I stand corrected, instead of using core data, Apple writes, 我坚持认为,苹果写道,而不是使用核心数据,

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. 但是,如果能够将BLOB作为资源存储在文件系统上,并能够维护到这些资源的链接(例如URL或路径),则更好。 You can then load a BLOB as and when necessary. 然后,您可以根据需要加载BLOB。

So you are doing it correctly, but maybe you should check out transformables. 因此,您做得正确,但是也许您应该检查可变形对象。 Just make sure you remove images you aren't using from memory if you are getting warnings 如果收到警告,只需确保从内存中删除不使用的图像

From documentation: https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html Under the section 'Large Data Objects (BLOBs)" 来自文档: https : //developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreData/Articles/cdPerformance.html在“大型数据对象(BLOB)”部分下

Another way to do it with a transformable: Which way to store data(image)? 使用可转换的另一种方式: 哪种方式存储数据(图像)? NSData, String or Transformable NSData,字符串或可转换

In fact, perhaps transformables are for core data at least: How should I store UIImages within my Core Data database? 实际上,也许可转换对象至少是用于核心数据的: 我应该如何在核心数据数据库中存储UIImage?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM