Using CGImageProperties to get EXIF properties

淺唱寂寞╮ 提交于 2019-12-10 14:47:09

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/7590741/using-cgimageproperties-to-get-exif-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!