4

I'm currently use binary data saved in Core Data object to generate UIImage as code below.

UIImage * postImage = [UIImage imageWithData:image];
double imageRatio = postImage.size.height / postImage.size.width;
[imageContent setFrame:CGRectMake(imageContent.frame.origin.x, imageContent.frame.origin.y, imageContent.frame.size.width, imageContent.frame.size.height * imageRatio)];
[imageContent setImage:postImage];

However, I found there's a little bit slow when generate image.
Should I save image locally when retrieve data from server instead?
Which way is faster?

Thanks,

Dranix
  • 551
  • 4
  • 11
  • 21
  • 1
    Check this out, this post will help you - http://stackoverflow.com/questions/2573072/coredata-store-images-to-db-or-not – rishi Apr 19 '12 at 05:01

3 Answers3

4

Save the image locally (e.g. in the Documents or Caches directory) instead of in the Core Data database. You get no benefit from storing binary data in the database as you will never search or index by this data, and it will just bloat your database. Just store an NSString reference to the filename/path you save the image to.

I imagine the UIImage:imageWithData method is slower when compared with reading an image from file that is already in a suitable image format.

Rob B
  • 1,485
  • 12
  • 16
1

save image locally and in your coreData save the location and name "URL" for that image

manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216
1

save your image locally such as PNG or JPEG instead of NSData.

Ayaz
  • 1,398
  • 15
  • 29