0

Is there a way to extract custom metadata from a PNG file with Objective-C? Other StackOverflow posts have libraries for Java or other languages, but none for Objective-C. We need to extract custom metadata from a PNG file from within an iOS app. The user choose an image from his/her Photo Gallery, and we will extract the custom metadata.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • possible duplicate of [How to get image metadata in ios](http://stackoverflow.com/questions/12478502/how-to-get-image-metadata-in-ios) – Malloc Jul 18 '14 at 02:02
  • @Malloc not a dupe because the other post doesn't address custom metadata? we specifically need custom metadata. – Crashalot Jul 18 '14 at 02:10

1 Answers1

3

You can use ImageIO framework to retrieve metadata of an image.

  1. Make sure you add ImageIo framework
  2. #import <ImageIO/ImageIO.h>
  3. Retrieve the metadata from local file or remote URL. Change the URL if you're using remote URL
NSURL *localFileUrl = [[NSBundle mainBundle] URLForResource:@"myImage" withExtension:@"png"];

CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)localFileUrl, NULL);

NSDictionary* imageProperties = (__bridge NSDictionary*) CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);

NSLog (@"image meta data %@", imageProperties);

Refer to ImageI/O programming guide if you want to do more advanced stuffs.

Subhransu
  • 108
  • 4
  • 1
    @Crashalot yes if you just want to retrieve custom metadata the above code should work. Refer to the sample code of [ImageApp](https://developer.apple.com/library/mac/samplecode/ImageApp/Listings/ImageInfoPanel_m.html) if you have some other requirements. But basically **ImageIO** is the answer! – Subhransu Jul 18 '14 at 03:27
  • Wow. It's taken me a while to find this. Thanks!! – Chris Prince Dec 11 '20 at 03:37