Created
August 11, 2015 06:42
-
-
Save edwardean/9a18df85e307881ead98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSURL *imageUrl; | |
CGImageSourceRef imageScorce = CGImageSourceCreateWithURL((__bridge CFURLRef)imageUrl, nil); | |
NSDictionary *options = @{(__bridge NSString *)kCGImageSourceCreateThumbnailFromImageIfAbsent:(id)kCFBooleanTrue, | |
(__bridge NSString *)kCGImageSourceCreateThumbnailWithTransform:(id)kCFBooleanTrue, | |
(__bridge NSString *)kCGImageSourceThumbnailMaxPixelSize:@128}; | |
CFRelease(imageScorce); | |
CGImageRef thumbImageRef = CGImageSourceCreateThumbnailAtIndex(imageScorce, 0, (__bridge CFDictionaryRef)options); | |
NSURL *targetUrl; | |
CGImageDestinationRef destinationRef = CGImageDestinationCreateWithURL((__bridge CFURLRef)targetUrl, kUTTypeJPEG, 1, nil); | |
if (!destinationRef) { | |
return; | |
} | |
NSDictionary *properties = @{(__bridge NSString *)kCGImageDestinationLossyCompressionQuality:@(0.94)}; | |
CGImageDestinationSetProperties(destinationRef, (__bridge CFDictionaryRef)properties); | |
CGImageDestinationAddImage(destinationRef, thumbImageRef, NULL); | |
bool ret = CGImageDestinationFinalize(destinationRef); | |
CFRelease(destinationRef); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment