Last active
August 29, 2015 14:14
-
-
Save allfake/eaedec47144accfdbb2b to your computer and use it in GitHub Desktop.
Ready to use fixed rotated image
This file contains 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
ALAssetRepresentation *assetRepresentation = [asset defaultRepresentation]; | |
CGImageRef fullResImage = [assetRepresentation fullResolutionImage]; | |
NSString *adjustment = [[assetRepresentation metadata] objectForKey:@"AdjustmentXMP"]; | |
if (adjustment) { | |
NSData *xmpData = [adjustment dataUsingEncoding:NSUTF8StringEncoding]; | |
CIImage *image = [CIImage imageWithCGImage:fullResImage]; | |
NSError *error = nil; | |
NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData | |
inputImageExtent:image.extent | |
error:&error]; | |
CIContext *context = [CIContext contextWithOptions:nil]; | |
if (filterArray && !error) { | |
for (CIFilter *filter in filterArray) { | |
[filter setValue:image forKey:kCIInputImageKey]; | |
image = [filter outputImage]; | |
} | |
fullResImage = [context createCGImage:image fromRect:[image extent]]; | |
} | |
} | |
UIImage *image = [UIImage imageWithCGImage:fullResImage | |
scale:[assetRepresentation scale] | |
orientation:(UIImageOrientation)[assetRepresentation orientation]]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment