我正在使用writeImageToSavedPhotosAlbum:metadata:completionBlock:将图像保存到相机胶卷(GPS 数据在传递给元数据的字典中)。然而,照片方向错误(因为我在拍照时翻转设备)。
还有另一个函数 writeImageToSavedPhotosAlbum:orientation:completionBlock: 但我无法传递 EXIF 数据。
根据文档,有 kCGImagePropertyOrientation属性来手动设置方向,但我在拍照并保存照片时检测设备的当前方向时遇到问题。
有人实现了用 EXIF 数据和正确方向保存图片吗?任何帮助将不胜感激。
这是我的代码:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
[self dismissModalViewControllerAnimated:YES];
[imageView setImage:image];
if(sourceCamera) {
//EXIF and GPS metadata dictionary
(...)
//saving image
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al writeImageToSavedPhotosAlbum:[image CGImage]
metadata:dict
completionBlock:^(NSURL *assetURL, NSError *error) {
if (error == nil) {
NSLog(@"saved");
} else {
NSLog(@"error");
}
}];
[al release];
}
}
最美好的祝愿,
一个。
最佳答案
设置kCGImagePropertyOrientation
时,您需要将UIImageOrientation值映射到相应的EXIF方向值。该映射是:
UIImageOrientationUp: 1
UIImageOrientationDown: 3
UIImageOrientationLeft: 8
UIImageOrientationRight: 6
UIImageOrientationUpMirrored: 2
UIImageOrientationDownMirrored: 4
UIImageOrientationLeftMirrored: 5
UIImageOrientationRightMirrored: 7
请注意,UIImageOrientationLeft 和 UIImageOrientationRight 与 the documentation 中您可能期望的相反。 ;如果将方向应用到直立图像,则会得到小样本图像,而不是应用方向时给出直立图像的原始图像数据的方向。
关于iphone - 如何在 iPhone 上保存带有 EXIF(GPS) 和方向的照片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6699330/