IOS无法获取png图像

时间:2017-10-30 11:29:55

标签: ios objective-c

我需要从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提交的内容。

我可以解决此问题>

1 个答案:

答案 0 :(得分:0)

我使用以下代码解决了问题

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
        }];
    }