iOS 8 UIImage Metadata

2019-05-19 13:24发布

问题:

This is my first question

I've a a "little" problem: when i read UIImage metadata on iOS 7 I use this code and it works great

 #pragma mark - Image Picker Controller delegate methods

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

    UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
    [self metaDataFromAssetLibrary:info];       
    [picker dismissViewControllerAnimated:YES completion:NULL];

}

From imagePickerController i choose the image and call metaDataFromAssetLibrary method

- (void) metaDataFromAssetLibrary:(NSDictionary*)info
{

    NSURL *assetURL = [info objectForKey:UIImagePickerControllerReferenceURL];

    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
    [library assetForURL:assetURL
             resultBlock:^(ALAsset *asset)  {

                        NSMutableDictionary *imageMetadata = nil;
                 NSDictionary *metadata = asset.defaultRepresentation.metadata;
                imageMetadata = [[NSMutableDictionary alloc] initWithDictionary:metadata];
                 NSLog (@"imageMetaData from AssetLibrary %@",imageMetadata);

             }
            failureBlock:^(NSError *error) {
                NSLog (@"error %@",error);
            }];

}

on Xcode5 and iOS7 console return something like this

imageMetaData from AssetLibrary {
    ColorModel = RGB;
    DPIHeight = 72;
    DPIWidth = 72;
    Depth = 8;
    Orientation = 1;
    PixelHeight = 2448;
    PixelWidth = 3264;
    "{Exif}" =     {
        ApertureValue = "2.52606882168926";
        BrightnessValue = "2.211389961389961";
        ColorSpace = 1;
        ComponentsConfiguration =         (
            1,
            2,
            3,
            0
        );
        DateTimeDigitized = "2014:06:05 08:54:09";
        DateTimeOriginal = "2014:06:05 08:54:09";
        ExifVersion =         (
            2,
            2,
            1
        );
        ExposureMode = 0;
        ExposureProgram = 2;
        ExposureTime = "0.05";
        FNumber = "2.4";
        Flash = 24;
        FlashPixVersion =         (
            1,
            0
        );
        FocalLenIn35mmFilm = 35;
        FocalLength = "4.28";
        ISOSpeedRatings =         (
            125
        );
        LensMake = Apple;
        LensModel = "iPhone 4S back camera 4.28mm f/2.4";
        LensSpecification =         (
            "4.28",
            "4.28",
            "2.4",
            "2.4"
        );
        MeteringMode = 3;
        PixelXDimension = 3264;
        PixelYDimension = 2448;
        SceneCaptureType = 0;
        SceneType = 1;
        SensingMethod = 2;
        ShutterSpeedValue = "4.321928460342146";
        SubjectArea =         (
            1643,
            1079,
            610,
            612
        );
        SubsecTimeDigitized = 347;
        SubsecTimeOriginal = 347;
        WhiteBalance = 0;
    };
    "{GPS}" =     {
        Altitude = 26;
        AltitudeRef = 1;
        DateStamp = "2014:06:05";
        DestBearing = "177.086387434555";
        DestBearingRef = M;
        ImgDirection = "357.0864197530864";
        ImgDirectionRef = M;
        Latitude = "43.80268";
        LatitudeRef = N;
        Longitude = "11.0635195";
        LongitudeRef = E;
        Speed = 0;
        SpeedRef = K;
        TimeStamp = "06:54:08";
    };
    "{MakerApple}" =     {
        1 = 0;
        3 =         {
            epoch = 0;
            flags = 1;
            timescale = 1000000000;
            value = 27688938393500;
        };
        4 = 1;
        5 = 186;
        6 = 195;
        7 = 1;
        8 =         (
            "-0.6805536",
            "0.02519802",
            "-0.755379"
        );
    };
    "{TIFF}" =     {
        DateTime = "2014:06:05 08:54:09";
        Make = Apple;
        Model = "iPhone 4S";
        Orientation = 1;
        ResolutionUnit = 2;
        Software = "8.0";
        XResolution = 72;
        YResolution = 72;
    };
}

But on Xcode6 and iOS 8 console return only this

imageMetaData from AssetLibrary {
    ColorModel = RGB;
    DPIHeight = 72;
    DPIWidth = 72;
    Depth = 8;
    Orientation = 1;
    PixelHeight = 768;
    PixelWidth = 1020;
    "{Exif}" =     {
        ColorSpace = 1;
        ComponentsConfiguration =         (
            1,
            2,
            3,
            0
        );
        ExifVersion =         (
            2,
            2,
            1
        );
        FlashPixVersion =         (
            1,
            0
        );
        PixelXDimension = 1020;
        PixelYDimension = 768;
        SceneCaptureType = 0;
    };
    "{TIFF}" =     {
        Orientation = 1;
        ResolutionUnit = 2;
        XResolution = 72;
        YResolution = 72;
    };
}

someone knows this problem?

any solution or suggestion?

Thank you so much

P.S.: excuse me for my terrible english ;-)

回答1:

After upgrade to Xcode6, you have to get the image in dismissViewController's completion block, or more complex method: get the image from asset.

Please try the following code:

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

    [picker dismissViewControllerAnimated:YES completion::^{
        UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage]; 
        [self metaDataFromAssetLibrary:info];       
    }];

Also you can reference john.k.doe's answer in didFinishPickingMediaWithInfo return nil photo