【问题标题】:How to read complete exif and tiff info of image in ios如何在ios中读取图像的完整exif和tiff信息
【发布时间】:2014-06-19 21:33:35
【问题描述】:

我正在尝试从图像中提取 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 数据 ....?

【问题讨论】:

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


    【解决方案1】:

    问题是您通过UIImage 来回传递它并通过UIImageJPEGRepresentation 转换为NSData,这将删除许多有趣的信息。直接加载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 中的 CGImageSourceRef

    【讨论】:

    • 我这样做了,我仍然看到有限的 exif 数据。我下载到 NSData 容器中的图像是一个 .THM 文件。你知道我的问题可能是什么吗?
    【解决方案2】:
    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);
    

    【讨论】:

      猜你喜欢
      • 2015-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 2011-07-30
      • 2020-05-24
      相关资源
      最近更新 更多