0

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. 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. 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_. When i need to get photos i get properties from db and then do [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. AND another question would be, how should i save photos fetched from web?

CarlHere
  • 43
  • 1
  • 11

1 Answers1

0

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. You can then load a BLOB as and when necessary.

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

Another way to do it with a transformable: Which way to store data(image)? NSData, String or Transformable

In fact, perhaps transformables are for core data at least: How should I store UIImages within my Core Data database?

Community
  • 1
  • 1
Alex
  • 3,861
  • 5
  • 28
  • 44
  • I know basics of core data. But i joined existing project witch was build using SQLite. Maybe there is another way of doing this? Maybe some optimization in what i do now? – CarlHere Jan 12 '15 at 14:10
  • If your database is only saving a file location, then it seems like you're doing it right. The memory warnings just mean you are loading too many images into memory at one time, you should try keeping less of them in memory at one time to solve that problem – Alex Jan 12 '15 at 14:20
  • What about saving binary data to database? Could that be more efficient? – CarlHere Jan 12 '15 at 14:38