Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <ImageIO/ImageIO.h>
- #import <MobileCoreServices/UTCoreTypes.h>
- static void CGImageWriteToFile(CGImageRef image, NSString *path, float compression)
- {
- NSURL *url = [NSURL URLWithString:path];
- if (![[url scheme] isEqualToString:@"file"])
- url = [NSURL fileURLWithPath:path];
- NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys:
- @(compression), kCGImageDestinationLossyCompressionQuality,
- nil];
- CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)url, kUTTypeJPEG, 1, (CFDictionaryRef)properties);
- CGImageDestinationAddImage(destination, image, nil);
- if (!CGImageDestinationFinalize(destination)) {
- NSLog(@"Failed to write image to %@", path);
- }
- CFRelease(destination);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement