读取照片的信息

阅读更多

前段时间写了一篇文章:读取照片的Exif信息,这篇文章则是使用了ImageIO类来获取照片的信息。

 

首先将ImageIO.framework导入项目中,然后导入头文件:

 

#import 

 

示例:

 

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"rails.png" withExtension:nil];
CGImageSourceRef myImageSource = CGImageSourceCreateWithURL((CFURLRef)modelURL, NULL);
CFDictionaryRef imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(myImageSource,0, NULL);
CFNumberRef imageWidth = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelWidth);
CFNumberRef imageHeight = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelHeight);

NSLog(@"%@", imagePropertiesDictionary);

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", h);

 

示例输出:

 

{
    ColorModel = RGB;
    Depth = 8;
    HasAlpha = 1;
    PixelHeight = 64;
    PixelWidth = 50;
    "{PNG}" =     {
        InterlaceType = 0;
        Software = "Adobe ImageReady";
    };
}
Image Width: 50
Image Height: 64
 

你可能感兴趣的:(iPhone,IOS,Exif)