首页 > 移动平台 > 详细

SSave ALAsset image to disk fast on iOS

时间:2014-04-12 17:40:20      阅读:485      评论:0      收藏:0      [点我收藏+]

I am using ALAsset to retrieve images like that:

[[asset defaultRepresentation] fullResolutionImage]]

This return CGImageRef which I want to save to disk as fast as possible...

Solution 1:

UIImage*currentImage =[UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]];
NSData*currentImageData =UIImagePNGRepresentation(currentImage);
[currentImageData writeToFile:filePath atomically:YES];

Solution 2:

CFURLRef url =(__bridge CFURLRef)[NSURL fileURLWithPath:filePath];
CGImageDestinationRef destination =CGImageDestinationCreateWithURL(url, kUTTypePNG,1, NULL);
CGImageDestinationAddImage(destination,[[asset defaultRepresentation] fullResolutionImage],nil);
CGImageDestinationFinalize(destination);

The problem is that both methods are very slow performing on a device. I takes about 2 seconds per image to perform this. And this is absolutely to long.

Question: How can I speed up this image saving process? Or perhaps is there a better solution for this?

UPDATE: The best performance improvements in both solutions is to save images to JPEG format instead of PNG. So for solution 1 have replaced UIImagePNGRepresentation with UIImageJPEGRepresentation. For solution 2 have replaced kUTTypePNG with kUTTypeJPEG.

Also worth noting that second solution is way more memory efficient that first one.

SSave ALAsset image to disk fast on iOS,布布扣,bubuko.com

SSave ALAsset image to disk fast on iOS

原文:http://www.cnblogs.com/lingzhao/p/3658398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!