库中图像的元数据

发布于 2024-10-06 00:18:50 字数 707 浏览 4 评论 0原文

我需要从库中获取图像的元数据。我正在使用的代码

- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info {
   NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

   ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

   [library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
       ALAssetRepresentation *representation = [asset defaultRepresentation];
       metadataDict = [representation metadata]; 
       NSLog(@"%@",metadataDict);


      } failureBlock:^(NSError *error) {
       NSLog(@"%@",[error description]);
      }];
   [library release];
}

我正在使用IOS 4.2 但我没有得到元数据。有人可以帮我解决这个问题吗?

I need to get the meta data of the image from the library. I am using the code

- (void)imagePickerController:(UIImagePickerController *)picker 
didFinishPickingMediaWithInfo:(NSDictionary *)info {
   NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

   ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

   [library assetForURL:assetURL resultBlock:^(ALAsset *asset) {
       ALAssetRepresentation *representation = [asset defaultRepresentation];
       metadataDict = [representation metadata]; 
       NSLog(@"%@",metadataDict);


      } failureBlock:^(NSError *error) {
       NSLog(@"%@",[error description]);
      }];
   [library release];
}

I am using IOS 4.2
But I am not getting the meta data.Can any one help me with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弃爱 2024-10-13 00:18:50

您发布的代码似乎没有任何问题。我已经在模拟器和设备上尝试过了,它可以工作。 Apple 的 metadata 方法文档指出:

如果系统无法解释该表示,则返回 nil。

因此,这很可能意味着您选择的图像没有任何元数据,或者图像的形式是库无法识别的。

您尚未在方法中定义 metadataDict,因此如果您想在块之外使用,则必须保留它。

metadataDict = [[representation metadata] retain];

可能您还必须使用 __block 标识符来声明它。

__block NSDictionary *metaDataDict;

There doesn't seem to be anything wrong with the code you posted. I have tried it in the simulator and on a device and it works. Apple's documentation for the metadata method states:

Returns nil if the representation is one that the system cannot interpret.

So this most likely means that the image you have chosen either doesn't have any metadata or the the image is in a form that the library doesn't recognize.

You have not defined metadataDict in your method so if you want to use outside of your block you have to retain it.

metadataDict = [[representation metadata] retain];

Possibly you have have to declare it with the __block identifier as well.

__block NSDictionary *metaDataDict;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文