简体   繁体   中英

iOS - Should we just save image as local file or as binary data (in Core Data object)? Which way is faster?

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,

Save the image locally (eg 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.

在本地保存图像并在coreData中保存该图像的位置和名称“URL”

在本地保存图像,如PNG或JPEG而不是NSData。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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