Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS-我们应该将图像保存为本地文件还是二进制数据(在核心数据对象中)?哪条路更快?_Iphone_Ios_Xcode - Fatal编程技术网

Iphone iOS-我们应该将图像保存为本地文件还是二进制数据(在核心数据对象中)?哪条路更快?

Iphone iOS-我们应该将图像保存为本地文件还是二进制数据(在核心数据对象中)?哪条路更快?,iphone,ios,xcode,Iphone,Ios,Xcode,我目前正在使用核心数据对象中保存的二进制数据生成UIImage,代码如下。 UIImage * postImage = [UIImage imageWithData:image]; double imageRatio = postImage.size.height / postImage.size.width; [imageContent setFrame:CGRectMake(imageContent.frame.origin.x, imageContent.frame.origin.y, i

我目前正在使用核心数据对象中保存的二进制数据生成UIImage,代码如下。

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];
但是,我发现生成图像时有点慢。
从服务器检索数据时是否应将图像保存在本地?
哪条路更快?


谢谢,

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

将图像保存在本地(例如,在文档或缓存目录中),而不是核心数据数据库中。在数据库中存储二进制数据并没有任何好处,因为您永远不会根据这些数据进行搜索或索引,而这只会使数据库膨胀。只需将NSString引用存储到您保存图像的文件名/路径即可


我认为UIImage:imageWithData方法比从已经具有合适图像格式的文件中读取图像要慢。

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

查看此内容,此帖子将对您有所帮助-