如何在iPhone上使用EXIF(GPS)和方位信息保存照片?

如何在iPhone上使用EXIF(GPS)和方位信息保存照片?,iphone,gps,orientation,exif,Iphone,Gps,Orientation,Exif,我正在使用它将图像保存到相机卷(GPS数据在字典中传递给元数据)。但是,图片方向错误(当我在拍照时翻转设备时) 还有另一个函数writeImageToSavedPhotosAlbum:orientation:completionBlock:但我无法传递EXIF数据 根据文档,有手动设置方向的属性,但我在拍摄和保存照片时检测设备的当前方向时遇到问题 是否有人使用EXIF数据和正确的方向保存了图片?任何帮助都将不胜感激 这是我的密码: - (void)imagePickerController:(U

我正在使用它将图像保存到相机卷(GPS数据在字典中传递给元数据)。但是,图片方向错误(当我在拍照时翻转设备时)

还有另一个函数writeImageToSavedPhotosAlbum:orientation:completionBlock:但我无法传递EXIF数据

根据文档,有手动设置方向的属性,但我在拍摄和保存照片时检测设备的当前方向时遇到问题

是否有人使用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];
    }
}
致以最良好的祝愿


a、

设置
kGimagePropertyOrientation
时,需要将UIImageOrientation值映射到相应的EXIF方向值。该映射是:

UIImageOrientationUp:             1
UIImageOrientationDown:           3
UIImageOrientationLeft:           8
UIImageOrientationRight:          6
UIImageOrientationUpMirrored:     2
UIImageOrientationDownMirrored:   4
UIImageOrientationLeftMirrored:   5
UIImageOrientationRightMirrored:  7

请注意,UIImageOrientationLeft和UIImageOrientationRight与您可能期望的相反;如果将方向应用于竖直图像,则会得到小样本图像,而不是应用方向时会产生竖直图像的原始图像数据的方向。

谢谢您的回答,您太棒了!就这么简单。。。找不到kCGImagePropertyOrientation和UIImageOrientation的任何单一解决方案。我就是喜欢这个板子!失范,这是有道理的,但在OP的代码中,他应该在哪里进行设置,以及如何进行设置?OP必须在某个地方为kCGImagePropertyOrientation设置一个值,对吗?@BenjaminWheeler需要修改
ALAsset
的元数据字典。一旦有了
ALAsset
,就可以通过以下方式获取元数据字典:
myMetadataDictionary=[[myAsset defaultRepresentation]metadata]
。然后,设置方向:
myMetadataDictionary[(NSString*)kCGImagePropertyOrientation]=orientation
,其中
orientation
是上面@Anomie给出的整数之一。