I use ALAsset to get these images:
[[asset defaultRepresentation] fullResolutionImage]]
This returns the CGImageRef, which I want to save to disk as quickly 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 on the device. For this, I take about 2 seconds per image. And it is absolutely long.
Question: How can I speed up this process of saving images? Or maybe there is a better solution for this?
UPDATE: The best performance improvements in both solutions are saving JPEG images instead of PNG. Therefore, for solution 1, the UIImagePNGRepresentation replaced by the UIImageJPEGRepresentation . For solution 2, replace kUTTypePNG with kUTTypeJPEG .
It is also worth noting that the second solution is a more efficient memory than the first.
Borut tomazin
source share