[英]iPhone OS image/photo resizing tool changing EXIF orientation data
[英]How to save photo with EXIF(GPS) AND orientation on iPhone?
我正在使用writeImageToSavedPhotosAlbum:metadata:completionBlock:将图像保存到相机胶卷(GPS 数据在字典中传递给元数据)。 但是图片方向错误(因为我在拍照时翻转设备)。
还有另一个 function 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 值 map 设置为相应的 EXIF 方向值。 该映射是:
UIImageOrientationUp: 1
UIImageOrientationDown: 3
UIImageOrientationLeft: 8
UIImageOrientationRight: 6
UIImageOrientationUpMirrored: 2
UIImageOrientationDownMirrored: 4
UIImageOrientationLeftMirrored: 5
UIImageOrientationRightMirrored: 7
请注意, UIImageOrientationLeft 和 UIImageOrientationRight 与您对文档的期望相反; 如果您将方向应用于直立图像,而不是原始图像数据的方向,则会在应用方向时提供直立图像,这些小样本图像就是您所获得的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.