Question

I'm brand new to objective-C and I'm trying to get exif data on some images in my Mac OS app. It looks like I need a C library to get the exif data, so I googled around, and found some C libraries, but I'm struggling on how to implement them.

1 Do I need to get a C library in order to read exif data on an image taken from a DSLR camera? (Thing like date taken)

  1. I tried this library http://libexif.sourceforge.net/ and I dug around on the site and downloaded from here: http://www.hmug.org/pub/MacOS_X/BSD/Libraries/Graphics/libexif/, which goes to this link: http://www.hmug.org/pub/MacOS_X/BSD/Libraries/Graphics/libexif/libexif-0.6.21-1-osx8.tar.gz

  2. I drug these files into xcode, and it looks like files are added correctly to my library, I think.enter image description here

  3. I'm not sure now how to now use these C classes. I tried including the files like this

    #include "exif-data.h"

    #include "exif-loader.h"

Is this right? Should I be doing it a different way?

  1. Then I'm really confused on the usage. On the documentation page here http://libexif.sourceforge.net/api/ it says

An application using libexif would typically first create an ExifLoader to load EXIF data into memory. From there, it would extract that data as an ExifData to start manipulating it. Each IFD is represented by its own ExifContent within that ExifData, which contains all the tag data in ExifEntry form. If the MakerNote data is required, an ExifMnoteData can be extracted from the ExifData and manipulated with the MakerNote functions.

What is the syntax for "creating an ExifLoader"?

Sorry for the noob questions! Any help is appreciated.

Was it helpful?

Solution 2

This post did it: http://devmacosx.blogspot.com/2011/07/nsimage-exif-metadata.html. I can now read all the exif data that I'm looking for.

OTHER TIPS

You can use Apples own API to get image Exif.

Here is a CGImageSource Reference And CGimageProperties

Her is a quick example:

 NSURL *imageFileURL = [NSURL fileURLWithPath:@"/Users/USERNAME/Documents/tasting_menu_004.jpg"];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)imageFileURL, NULL);
NSDictionary *treeDict;
NSMutableString *exifData;


NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:NO], (NSString *)kCGImageSourceShouldCache,
                         nil];


CFDictionaryRef imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, ( CFDictionaryRef)options);
CFRelease(imageSource);
if (imageProperties) {
    treeDict = [NSDictionary dictionaryWithDictionary:(NSDictionary*)(imageProperties)];
    id exifTree = [treeDict objectForKey:@"{Exif}"];



    exifData = [NSMutableString stringWithString:@""];



    for (NSString *key in [[exifTree allKeys] sortedArrayUsingSelector:@selector(compare:)])
    {


        NSString* locKey = [[NSBundle bundleWithIdentifier:@"com.apple.ImageIO.framework"] localizedStringForKey:key value:key table: @"CGImageSource"];

        id  value = [exifTree  valueForKey:key]  ;


                   [exifData appendFormat:@"key =%@ ; Value = %@ \n", locKey,value];




    }
 NSLog(@" exifData %@", exifData);

Log -->exifData

key =Aperture Value ; Value = 4.643856

key =Color Space ; Value = 65535

key =Custom Rendered ; Value = 0

key =Date Time Digitized ; Value = 2013:06:13 08:35:07

key =Date Time Original ; Value = 2013:06:13 08:35:07

key =Exif Version ; Value = ( 2, 2, 1 )

key =Exposure Bias Value ; Value = 0

key =Exposure Mode ; Value = 1

key =Exposure Program ; Value = 1

key =Exposure Time ; Value = 0.0125

key =FNumber ; Value = 5

key =Flash ; Value = 9

key =Focal Length ; Value = 17

key =Focal Plane Resolution Unit ; Value = 2

key =Focal Plane X Resolution ; Value = 3849.211788896504

key =Focal Plane Y Resolution ; Value = 3908.141962421712

key =ISO Speed Ratings ; Value = ( 800 )

key =Max Aperture Value ; Value = 4

key =Metering Mode ; Value = 5

key =Pixel X Dimension ; Value = 5181

key =Pixel Y Dimension ; Value = 3454

key =Scene Capture Type ; Value = 0

key =Shutter Speed Value ; Value = 6.321928

key =Subject Distance ; Value = 1.22

key =Sub-second Time Digitized ; Value = 25

key =Sub-second Time Original ; Value = 25

key =White Balance ; Value = 0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top