欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

读取照片的信息 博客分类: iOS iPhoneIOSExif 

程序员文章站 2024-02-14 19:15:10
...

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

 

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

 

#import <ImageIO/ImageIO.h>

 

示例:

 

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