How to get exif information from ALAsset?

2019-08-13 00:49发布

问题:

I need to get exif information from selected asset and to display part of it on the screen.

回答1:

[[asset defaultRepresentation] metadata];

returns a dictionary of dictionaries of metadata for the given asset representation. Check out this dictionary for the data you're interested in. I am not sure but I think the keys in that dictionary (and subdictionaries) are the same as the ones listed under CGImageProperties Reference.



回答2:

This is a complete answer ... all in one spot

NSDictionary *nsd = [[asset3 defaultRepresentation] metadata];
    NSString *widthStr = [nsd objectForKey: @"PixelWidth"];
    NSString *heightStr = [nsd objectForKey: @"PixelHeight"];

    NSLog(@"nsd: %@ ... widthStr: %@ ... heightStr: %@ ...", nsd, widthStr, heightStr);

output:

nsd: {
    ColorModel = RGB;
    DPIHeight = 72;
    DPIWidth = 72;
    Depth = 8;
    Orientation = 1;
    PixelHeight = 1136;
    PixelWidth = 642;
    "{Exif}" =     {
        ColorSpace = 1;
        ComponentsConfiguration =         (
            1,
            2,
            3,
            0
        );
        ExifVersion =         (
            2,
            2,
            1
        );
        FlashPixVersion =         (
            1,
            0
        );
        PixelXDimension = 642;
        PixelYDimension = 1136;
        SceneCaptureType = 0;
    };
    "{TIFF}" =     {
        Orientation = 1;
        ResolutionUnit = 2;
        XResolution = 72;
        YResolution = 72;
    };
} ... widthStr: 642 ... heightStr: 1136 ...