使用 CGImageProperties 获取 EXIF 属性

发布于 2024-12-07 06:00:16 字数 1346 浏览 0 评论 0原文

我希望能够向 JPEG 的元数据添加文本注释,并能够从 iPhone 应用程序中读回它。

我认为这会相当简单,因为 ios4 包含对 EXIF 信息的支持。因此,我使用名为“used AnalogExif”的 Windows 工具添加了元数据,并使用以下命令从我的应用程序中读回它:

NSData *jpeg = UIImageJPEGRepresentation(myUIImage,1.0);

CGImageSourceRef  source = CGImageSourceCreateWithData((CFDataRef)jpeg, NULL);
NSDictionary *metadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source,0,NULL);

NSMutableDictionary *metadataAsMutable = [[metadata mutableCopy]autorelease];
[metadata release];

NSMutableDictionary *EXIFDictionary = [[[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary]

这在某种程度上有效......

我在元数据字典中得到的内容类似于:

(gdb) po metadata
{
   ColorModel = RGB;
   Depth = 8;
   Orientation = 1;
   PixelHeight = 390;
   PixelWidth = 380;
   "{Exif}" =     {
      ColorSpace = 1;
      PixelXDimension = 380;
      PixelYDimension = 390;
   };
   "{JFIF}" =     {
      DensityUnit = 0;
      JFIFVersion = (
        1,
        1
      );
      XDensity = 1;
      YDensity = 1;
   };
   "{TIFF}" =     {
      Orientation = 1;
   };
}

但这就是我所能得到的!我已经用我能找到的每个 EXIF 编辑器(我应该说主要是 PC 编辑器)编辑了 JPEG 文件,尽管他们都说我添加了 JPEG 注释和 EXIF 标题和关键字,但 Apple SDK 似乎无法提供这些信息在我的应用程序中。

有没有人设法在 jpeg 的元数据中设置文本字段并设法从 iphone 应用程序中读取它?

如果可能的话,我不想使用第三方库,

提前非常感谢

I want to be able to add a text comment to the metadata of a JPEG and be able to read it back from within an iphone app.

I thought this would be fairly simple as ios4 contains support for EXIF info. So I added metadata using a Windows tool called used AnalogExif and read it back from my app using:

NSData *jpeg = UIImageJPEGRepresentation(myUIImage,1.0);

CGImageSourceRef  source = CGImageSourceCreateWithData((CFDataRef)jpeg, NULL);
NSDictionary *metadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source,0,NULL);

NSMutableDictionary *metadataAsMutable = [[metadata mutableCopy]autorelease];
[metadata release];

NSMutableDictionary *EXIFDictionary = [[[metadataAsMutable objectForKey:(NSString *)kCGImagePropertyExifDictionary]

And that works...to a point :)

What I get back in the metadata dictionary is something like:

(gdb) po metadata
{
   ColorModel = RGB;
   Depth = 8;
   Orientation = 1;
   PixelHeight = 390;
   PixelWidth = 380;
   "{Exif}" =     {
      ColorSpace = 1;
      PixelXDimension = 380;
      PixelYDimension = 390;
   };
   "{JFIF}" =     {
      DensityUnit = 0;
      JFIFVersion = (
        1,
        1
      );
      XDensity = 1;
      YDensity = 1;
   };
   "{TIFF}" =     {
      Orientation = 1;
   };
}

But thats all I can get! I've edited the JPEG file with every EXIF editor I can find (mostly PC ones I should say) and although they all say I have added JPEG comments and EXIF captions and keywords, none of that info seems to be available from the Apple SDK in my app.

Has anyone managed to set a text field in the metadata of a jpeg and manage to read it back from an iphone app?

I didn't want to use a third party library if at all possible

many thanks in advance

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

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

发布评论

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

评论(1

攒眉千度 2024-12-14 06:00:16

您认为 iOS 确实支持比您所看到的更多的元数据,这是正确的。当您创建 UIImage 然后将其转换回 JPEG 时,您可能会丢失数据。尝试 NSData *jpeg = [NSData dataWithContentsOfFile:@"foo.jpg"] 你应该会看到 EXIF。

You're correct in thinking that iOS does support more metadata than what you're seeing. You probably lost the data when you created a UIImage and then converted it back to JPEG. Try NSData *jpeg = [NSData dataWithContentsOfFile:@"foo.jpg"] and you should see the EXIF.

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