In the code below, I crashed on the line CGImageDestinationFinalize (). CGImage - a large photo in JPG format. It works fine if I use a smaller JPG. But something more than 10 MB falls on the device with "out of memory".
I think the CGImageDestination * methods pass the record, but I have to do something wrong that saves the data.
Is there any other API call that I should use when writing large JPGs?
BOOL SKImageWriteToDisk(CGImageRef image, NSURL *url, SKImageProfile profile, CGFloat dpi) { CFStringRef type = profile == SKmageProfileCompressed ? kUTTypeJPEG : kUTTypePNG; CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)url, type, 1, NULL); if (!destination) { return NO; } NSMutableDictionary *properties = [@{ (id) kCGImagePropertyDPIHeight: @(dpi), (id) kCGImagePropertyDPIWidth: @(dpi) } mutableCopy]; if (profile == SKImageProfileCompressed) { properties[(id) kCGImageDestinationLossyCompressionQuality] = @(0.8f); } CGImageDestinationAddImage(destination, image, (__bridge CFDictionaryRef)properties); BOOL finalizeSuccess = CGImageDestinationFinalize(destination);
source share