开发者

Using CGImageProperties to get EXIF properties

开发者 https://www.devze.com 2023-04-08 22:32 出处:网络
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 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];

NSMutableDictiona开发者_C百科ry *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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消