iOS 8 UIImage元数据

时间:2014-06-15 07:44:24

标签: uiimage metadata uiimagepickercontroller ios8 xcode6

这是我的第一个问题

我有一个“小”问题: 当我在iOS 7上阅读UIImage元数据时,我使用此代码并且效果很好

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

}

从imagePickerController我选择图像并调用metaDataFromAssetLibrary方法

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

}

在Xcode5和iOS7控制台上返回类似这样的内容

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

但是在Xcode6和iOS 8控制台上只返回此

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;
    };
}
有人知道这个问题吗?

任何解决方案或建议?

非常感谢

P.S。:请原谅我可怕的英语; - )

1 个答案:

答案 0 :(得分:2)

升级到Xcode6后,你必须在dismissViewController的完成块或更复杂的方法中获取图像:从资产中获取图像。

请尝试以下代码:

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

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

你也可以参考john.k.doe的回答 didFinishPickingMediaWithInfo return nil photo