读取照片的Exif信息,这篇文章则是使用了ImageIO类来获取照片的信息

来源:互联网 发布:弘历软件下载 编辑:程序博客网 时间:2024/05/16 18:09


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

 

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

 

Ios代码  收藏代码
  1. #import <ImageIO/ImageIO.h>  

 

示例:

 

Ios代码  收藏代码
  1. NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"rails.png" withExtension:nil];  
  2. CGImageSourceRef myImageSource = CGImageSourceCreateWithURL((CFURLRef)modelURL, NULL);  
  3. CFDictionaryRef imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(myImageSource,0, NULL);  
  4. CFNumberRef imageWidth = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelWidth);  
  5. CFNumberRef imageHeight = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelHeight);  
  6.   
  7. NSLog(@"%@", imagePropertiesDictionary);  
  8.   
  9. int w = 0;  
  10. int h = 0;  
  11.   
  12. CFNumberGetValue(imageWidth, kCFNumberIntType, &w);  
  13. CFNumberGetValue(imageHeight, kCFNumberIntType, &h);  
  14.   
  15. CFRelease(imagePropertiesDictionary);  
  16. CFRelease(myImageSource);  
  17.   
  18. printf("Image Width: %d\n", w);  
  19. printf("Image Height: %d", h);  

 

示例输出:

 

Ios代码  收藏代码
  1. {  
  2.     ColorModel = RGB;  
  3.     Depth = 8;  
  4.     HasAlpha = 1;  
  5.     PixelHeight = 64;  
  6.     PixelWidth = 50;  
  7.     "{PNG}" =     {  
  8.         InterlaceType = 0;  
  9.         Software = "Adobe ImageReady";  
  10.     };  
  11. }  
  12. Image Width: 50  
  13. Image Height: 64  
 


原创粉丝点击