Iphone 2D 绘图 - 如何获取图片属性?

来源:互联网 发布:吉林顺通网络的骗局 编辑:程序博客网 时间:2024/05/17 04:56

如何获取图片属性,例如一个图片的高度和长度、DPI、EXIF数据等?

在Mac OS X 10.4的Mac系统和IOS4的IOS系统中都已经介绍了ImageIO框架,它提供一个功能从一个图片中获取图片属性例如大小、DPI、EXIF数据等。

获取图片属性:

1、为你的图片创建一个 CGImageSourceRef。

2、调用CGImageSourceCopyPropertiesAtIndex获得图片属性字典的拷贝

3、调用CFDictionaryGetValue中你感兴趣的属性键来获取字典内的数字,可用的键都存在 CGImageProperties Reference


以下是一个例子让你如果获取图片的宽度和高度

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

原创粉丝点击