1

私のアプリケーションでは、特定の URL リンクから画像をダウンロードし、それを に割り当てる必要がありますUIImageView。その画像をライブラリに保存しません。この場合、アプリでこの画像の Exif データ( EXIF_TAG_CREATE_DATE、など) を取得するにはどうすればよいですか?EXIF_TAG_ARTIST

4

2 に答える 2

5

ImageIO を介して、画像の高さと幅、DPI、EXIF データなどの画像プロパティにアクセスする

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);

( ソース: 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]);

( ソース: http://blog.depicus.com/index.php/2011/05/07/getting-exif-data-from-images-on-ios/ )

オープン ソース (ただし時代遅れ) の iphone-exif ライブラリ経由で EXIF プロパティにアクセスする

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];

( ソース: http://code.google.com/p/iphone-exif/ )

于 2013-05-30T08:08:14.790 に答える