`
jsntghf
  • 浏览: 2480476 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

读取照片的信息

    博客分类:
  • iOS
阅读更多

前段时间写了一篇文章:读取照片的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
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics