gpt4 book ai didi

ios - GPSDictionary 返回 nil,uiimage 的元数据中没有 exif 位置数据

转载 作者:行者123 更新时间:2023-11-29 00:00:18 26 4
gpt4 key购买 nike

以下屏幕截图显示了打印元数据时显示的内容,旁边是已导出到我的 Mac 的完全相同的图像,因此我可以查看图片中的所有数据(注意:两者都没有被修改,因此它们完全相同)。 enter image description here

我用来获取位置数据的代码如下:

    UIImage *image = (UIImage*)[info objectForKey:UIImagePickerControllerOriginalImage];
NSData *data = UIImageJPEGRepresentation( image, 0.9f );
// EXIF DATA
CGImageSourceRef mySourceRef = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);

if (mySourceRef != NULL)
{
NSDictionary *myMetadata = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex(mySourceRef, 0, NULL);
NSDictionary *GPSDictionary = [myMetadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary];
NSLog( @"%@", myMetadata );
// NSLog([GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLongitude]);
// NSLog([GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLatitude]);

NSLog( @"%@", [GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLongitude]);
NSLog( @"%@", [GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLatitude]);

}

编辑:为了澄清,该应用程序有权使用相机胶卷和相机等。还在其他 iPhone 设备上进行了测试,以确保不仅仅是 iPhone X 问题

最佳答案

发现问题是因为我试图从临时图片中获取 GPS 数据,该图片基本上是 Assets 的重复 jpeg 表示形式。解决此问题的方法是通过执行以下操作从 Original Assets 获取 EXIF 数据:

    NSURL *assetURL = (NSURL*)[info objectForKey:UIImagePickerControllerReferenceURL];
NSData *originalData = (NSData*) [self retrieveAssetDataPhotosFramework:assetURL];
CGImageSourceRef mySourceRef = CGImageSourceCreateWithData((CFDataRef)originalData, NULL);

if (mySourceRef != NULL)
{
NSDictionary *myMetadata = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex(mySourceRef,0,NULL);
NSDictionary *GPSDictionary = [myMetadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary];
NSLog( @"%@", myMetadata );
NSLog( @"%@", [GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLongitude]);
NSLog( @"%@", [GPSDictionary valueForKey:(NSString*)kCGImagePropertyGPSLatitude]);

}

为了获取 Assets URL,我使用了一种在此处找到的方法(现在无法找到要发布的链接)

- (NSData *)retrieveAssetDataPhotosFramework:(NSURL *)urlMedia  {

__block NSData *iData = nil;

PHFetchResult *result = [PHAsset fetchAssetsWithALAssetURLs:@[urlMedia] options:nil];
PHAsset *asset = [result firstObject];

PHImageManager *imageManager = [PHImageManager defaultManager];
PHImageRequestOptions *options = [[PHImageRequestOptions alloc]init];
options.synchronous = YES;
options.version = PHImageRequestOptionsVersionCurrent;

@autoreleasepool {
[imageManager requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
iData = [imageData copy];
NSLog(@"requestImageDataForAsset returned info(%@)", info);
}];
}

assert(iData.length != 0);
return iData;
}

关于ios - GPSDictionary 返回 nil,uiimage 的元数据中没有 exif 位置数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49669886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com