Ios7 AlassetLibrary返回没有外部裁剪或其他过滤器的图像
我在iOS7上有一个奇怪的问题 用户可以在照片应用程序中打开图像并进行裁剪 在我的应用程序中,当我尝试获取图像时,它会在没有裁剪的情况下返回。其他编辑(如旋转)将保留 我介绍了没有编辑功能的图像选择器 我的代码:Ios7 AlassetLibrary返回没有外部裁剪或其他过滤器的图像,ios7,uiimagepickercontroller,alassetslibrary,Ios7,Uiimagepickercontroller,Alassetslibrary,我在iOS7上有一个奇怪的问题 用户可以在照片应用程序中打开图像并进行裁剪 在我的应用程序中,当我尝试获取图像时,它会在没有裁剪的情况下返回。其他编辑(如旋转)将保留 我介绍了没有编辑功能的图像选择器 我的代码: ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init]; [assetLibrary assetForURL:[info valueForKey:UIImagePickerControllerReferenceURL]
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:[info valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *rep = [asset defaultRepresentation];
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
NSData *data = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];//this is NSData may be what you want
editedImage = [UIImage imageWithData:data];
} failureBlock:^(NSError *err) {
NSLog(@"Error: %@",[err localizedDescription]);
}];
如果我使用
UIImage *image = info[UIImagePickerControllerOriginalImage];
content = UIImageJPEGRepresentation(image, 1.0);
图像被正确裁剪
这是iOS7中的一个bug吗?事实证明,裁剪实际上保存在元数据中 以下是我最后做的:
ALAssetRepresentation *rep = [asset defaultRepresentation];
NSString *xmpString = rep.metadata[@"AdjustmentXMP"];
if(xmpString)
{
NSData *xmpData = [xmpString dataUsingEncoding:NSUTF8StringEncoding];
CIImage *image = [CIImage imageWithCGImage:rep.fullResolutionImage];
NSError *error = nil;
NSArray *filterArray = [CIFilter filterArrayFromSerializedXMP:xmpData
inputImageExtent:image.extent
error:&error];
if (error)
{
DM_FLOG(@"ERROR:: Error during CIFilter creation: %@", [error localizedDescription]);
}
for (CIFilter *filter in filterArray) {
[filter setValue:image forKey:kCIInputImageKey];
image = [filter outputImage];
}
CIContext* context = [CIContext contextWithOptions:nil];
CGImageRef cgImage = [context createCGImage:image fromRect:[image extent]];
context = nil;
image = nil;
contentType = @"image/jpeg";
content = UIImageJPEGRepresentation([UIImage imageWithCGImage:cgImage], 1.0);
CGImageRelease(cgImage);
}
else
{
Byte *buffer = (Byte*)malloc(rep.size);
NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:rep.size error:nil];
content = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
}