如何在ios中阅读完整的图像exif和tiff信息

时间:2014-05-03 06:18:03

标签: ios cocoa-touch image-processing ios7 exif

我正在尝试从图像中提取exif信息。

UIImage *pImage = [UIImage imageNamed:@"IMG_0011.JPG"];
NSData* pngData =  UIImageJPEGRepresentation(pImage, 1.0);

CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)pngData, NULL);
NSDictionary *metadata = (__bridge NSDictionary *) CGImageSourceCopyPropertiesAtIndex(source, 0, NULL);
NSLog(@"exif %@" , metadata);

我收到了以下元数据信息

exif {
    ColorModel = RGB; <br>
    Depth = 8; <br>
    Orientation = 1; <br>
    PixelHeight = 1936;<br>
    PixelWidth = 2592;<br>
    "{Exif}" =     {
        ColorSpace = 1;<br>
        PixelXDimension = 2592;<br>
        PixelYDimension = 1936;<br>
    };
    "{JFIF}" =     {<br>
        DensityUnit = 0;<br>
        JFIFVersion =         (<br>
            1,<br>
            1<br>
        );
        XDensity = 1;<br>
        YDensity = 1;<br>
    };
    "{TIFF}" =     {<br>
        Orientation = 1;<br>
    };
}<br>

但是当我使用exif数据查看器或预览应用程序检查图像后,我得到了信息。

Aperture Value: 2.526<br>
Brightness Value: 1.897<br>
Color Space: sRGB<br>
Components Configuration: 1, 2, 3, 0<br>
Date Time Digitized: 20-Dec-2013 1:33:31 PM<br>
Date Time Original: 20-Dec-2013 1:33:31 PM<br>
Exif Version: 2.2.1<br>
Exposure Mode: Auto exposure<br>
Exposure Program: Normal program<br>
Exposure Time: 1/15<br>
Flash: No flash function<br>
FlashPix Version: 1.0<br>
FNumber: 2.4
Focal Length: 4.28<br>
Focal Length In 35mm Film: 35<br>
ISO Speed Ratings: 125<br>
Metering Mode: Pattern<br>
Pixel X Dimension: 2,592<br>
Pixel Y Dimension: 1,936<br>
Scene Capture Type: Standard<br>
Sensing Method: One-chip color area sensor<br>
Shutter Speed Value: 3.907
Subject Area: 1295, 967, 699, 696
White Balance: Auto white balance<br>
Regions: {
    HeightAppliedTo = 1936;<br>
    RegionList =     (
                {
            ConfidenceLevel = 326;<br>
            FaceID = 3;<br>
            Height = "0.172";<br>
            Timestamp = 956449648;<br>
            Type = Face;<br>
            Width = "0.128";
            X = "0.542";<br>
            Y = "0.426";<br>
        }
    );
    WidthAppliedTo = 2592; <br>
}

任何建议如何在ios上提取完整的exif数据....?

2 个答案:

答案 0 :(得分:2)

问题在于,您通过UIImage对此进行了四舍五入,并通过NSData转换为UIImageJPEGRepresentation,这将删除大量有趣的信息。只需直接加载NSData

NSString *path = [[NSBundle mainBundle] pathForResource:@"IMG_0011" ofType:@"JPG"];
NSData *pngData = [NSData dataWithContentsOfFile:path];

CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)pngData, NULL);
NSDictionary *metadata = CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source, 0, NULL));
NSLog(@"exif %@" , metadata);
CFRelease(source);
顺便说一句,不要忘记“Create Rule”,即名称中CreateCopy的Core Foundation功能正在将所有权转让给您,并且您负责自己释放物体。例如,您可以使用__bridge_transferCFBridgingRelease将源属性字典的所有权转移到ARC。您可以明确CFRelease的{​​{1}}。

答案 1 :(得分:1)

CGImageSourceRef myImageSource;

myImageSource = CGImageSourceCreateWithURL(url, NULL);

CFDictionaryRef props = CGImageSourceCopyPropertiesAtIndex(myImageSource,0, NULL);

NSDictionary *exif = [(__bridge NSDictionary *)props objectForKey : (NSString *)kCGImagePropertyExifDictionary];
NSString *dateTimeString = [exif objectForKey:(NSString *)kCGImagePropertyExifDateTimeOriginal];


CFRelease(props);
CFRelease(myImageSource);