In my application , I need to download the image from particular URL Link and assign that to UIImageView
. I do not store that image to my Library, then in this case how can I get the Exif data of this image (like EXIF_TAG_CREATE_DATE
, EXIF_TAG_ARTIST
, etc) in my app?
Asked
Active
Viewed 2,319 times
1
-
Does this help? http://stackoverflow.com/questions/7590741/using-cgimageproperties-to-get-exif-properties – trojanfoe May 30 '13 at 07:27
2 Answers
5
Accessing image properties, such as image height and width, DPI, EXIF data, etc., via ImageIO
CFURLRef url = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, (const UInt8 *)inputFileName, strlen(inputFileName), false);
if (!url) {
printf ("* * Bad input file path\n");
}
CGImageSourceRef myImageSource;
myImageSource = CGImageSourceCreateWithURL(url, NULL);
CFDictionaryRef imagePropertiesDictionary;
imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(myImageSource,0, NULL);
CFNumberRef imageWidth = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelWidth);
CFNumberRef imageHeight = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelHeight);
int w = 0;
int h = 0;
CFNumberGetValue(imageWidth, kCFNumberIntType, &w);
CFNumberGetValue(imageHeight, kCFNumberIntType, &h);
CFRelease(imagePropertiesDictionary);
CFRelease(myImageSource);
printf("Image Width: %d\n",w);
printf("Image Height: %d\n",h);
( source: http://developer.apple.com/library/ios/#qa/qa1654/_index.html )
NSString *myPath = [[NSBundle mainBundle] pathForResource:@"IMG_2733" ofType:@"JPG"];
NSURL *myURL = [NSURL fileURLWithPath:myPath];
CGImageSourceRef mySourceRef = CGImageSourceCreateWithURL((CFURLRef)myURL, NULL);
NSDictionary *myMetadata = (NSDictionary *) CGImageSourceCopyPropertiesAtIndex(mySourceRef,0,NULL);
NSDictionary *exifDic = [myMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary];
NSDictionary *tiffDic = [myMetadata objectForKey:(NSString *)kCGImagePropertyTIFFDictionary];
NSLog(@"exifDic properties: %@", myMetadata); //all data
float rawShutterSpeed = [[exifDic objectForKey:(NSString *)kCGImagePropertyExifExposureTime] floatValue];
int decShutterSpeed = (1 / rawShutterSpeed);
NSLog(@"Camera %@",[tiffDic objectForKey:(NSString *)kCGImagePropertyTIFFModel]);
NSLog(@"Focal Length %@mm",[exifDic objectForKey:(NSString *)kCGImagePropertyExifFocalLength]);
NSLog(@"Shutter Speed %@", [NSString stringWithFormat:@"1/%d", decShutterSpeed]);
NSLog(@"Aperture f/%@",[exifDic objectForKey:(NSString *)kCGImagePropertyExifFNumber]);
NSNumber *ExifISOSpeed = [[exifDic objectForKey:(NSString*)kCGImagePropertyExifISOSpeedRatings] objectAtIndex:0];
NSLog(@"ISO %i",[ExifISOSpeed integerValue]);
NSLog(@"Taken %@",[exifDic objectForKey:(NSString*)kCGImagePropertyExifDateTimeDigitized]);
( source: http://blog.depicus.com/index.php/2011/05/07/getting-exif-data-from-images-on-ios/ )
Accessing EXIF properties via the open source (but outdated) iphone-exif library
NSData* theImageData = UIImageRepresentation(anImage,1.0);
EXFJpeg* jpegScanner = [[EXFJpeg alloc] init];
[jpegScanner scanImageData: theImageData];
EXFMetaData* exifData = jpegScanner.exifMetaData; EXFJFIF* jfif =
jpegScanner.jfif;
id tagValue = [exifData tagValue: aTagId];
( source: http://code.google.com/p/iphone-exif/ )

magma
- 8,432
- 1
- 35
- 33
0
try this
NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager]
attributesOfItemAtPath:@"imagePath" error:&error];
if (!error)
{
NSLog(@"file attributes : %@",attributes);
}
and this is the result :
NSFileCreationDate = "2013-05-28 09:29:37 +0000";
NSFileExtensionHidden = 0;
NSFileGroupOwnerAccountID = 20;
NSFileGroupOwnerAccountName = staff;
NSFileModificationDate = "2013-05-28 09:29:37 +0000";
NSFileOwnerAccountID = 502;
NSFileOwnerAccountName = lerhan;
NSFilePosixPermissions = 420;
NSFileReferenceCount = 1;
NSFileSize = 1494;
NSFileSystemFileNumber = 46795419;
NSFileSystemNumber = 234881026;
NSFileType = NSFileTypeRegular;
to access any data type NSLog(@"file creation date : %@",[attributes objectForKey:@"NSFileCreationDate"]);

Liolik
- 791
- 6
- 12
-
1
-
Its returns the attributes to nil value while i am using share extension – Deepak Saki Feb 10 '17 at 12:26
-
This is not the EXIF metadata. This is the file metadata, they are different. The creation date here is not equal to the taken on date of the photo, for example. – derek Sep 12 '22 at 16:03