【问题标题】:IOS Cannot get exif data for png imageIOS无法获取png图像的exif数据
【发布时间】:2017-10-30 11:29:55
【问题描述】:

我需要从存储为元数据的 png 图像中提取描述部分。

当我从 linux 运行命令 exiftool outimage.png 时,我会得到类似的详细信息

ExifTool Version Number         : 10.10
File Name                       : outimage.png
Directory                       : .
File Size                       : 387 kB
File Modification Date/Time     : 2017:10:30 12:18:23+05:30
File Access Date/Time           : 2017:10:30 12:18:26+05:30
File Inode Change Date/Time     : 2017:10:30 12:18:23+05:30
File Permissions                : rw-rw-r--
File Type                       : PNG
File Type Extension             : png
MIME Type                       : image/png
Image Width                     : 1080
Image Height                    : 1080
Bit Depth                       : 8
Color Type                      : RGB with Alpha
Compression                     : Deflate/Inflate
Filter                          : Adaptive
Interlace                       : Noninterlaced
Pixels Per Unit X               : 11811
Pixels Per Unit Y               : 11811
Pixel Units                     : meters
Description                     : Hi
Image Size                      : 1080x1080
Megapixels                      : 1.2

Description 将存储我的自定义数据,现在我需要从 ios 目标中检索这些数据,请参阅代码。所以我将相同的图像下载到 iPhone 并使用下面的代码我没有得到所有的元数据

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    //get eix data
     UIImage *orignalImage = [info valueForKey:UIImagePickerControllerOriginalImage];
     NSData *pngDataOriginal = UIImagePNGRepresentation(orignalImage);
     CGImageSourceRef source = CGImageSourceCreateWithData( (CFDataRef) pngDataOriginal, NULL);
    NSDictionary* metadata = (NSDictionary *)CFBridgingRelease(CGImageSourceCopyPropertiesAtIndex(source,0,NULL));
    NSLog(@" exifData %@", metadata);
}

哪个打印

exifData {
    ColorModel = RGB;
    Depth = 8;
    HasAlpha = 1;
    PixelHeight = 1080;
    PixelWidth = 1080;
    "{PNG}" =     {
        Chromaticities =         (
            "0.3127",
            "0.329",
            "0.64",
            "0.33",
            "0.3",
            "0.6",
            "0.15",
            "0.06"
        );
        Gamma = "0.45455";
        InterlaceType = 0;
        sRGBIntent = 0;
    };
}

而且它不包括Description 归档。

我可以解决这个问题>

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    我已经使用以下代码解决了这个问题

    NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
    
        if(referenceURL) {
            ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
            [library assetForURL:referenceURL resultBlock:^(ALAsset *asset) {
                ALAssetRepresentation *rep = [asset defaultRepresentation];
                NSDictionary *metadata = rep.metadata;
                NSLog(@"image data %@", metadata);
    
    
            } failureBlock:^(NSError *error) {
                // error handling
            }];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-28
      • 1970-01-01
      • 2018-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多