uiimage - iOS 8 UIImage 元数据

标签 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.:请原谅我糟糕的英语;-)

最佳答案

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

请尝试以下代码:

- (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

关于uiimage - iOS 8 UIImage 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24227578/

相关文章:

linux - Spotify dbus 请求返回空元数据

metadata - RavenDB 更改元数据 "Raven-Entity-Name"

iphone - 如何使用 UIImagePickerControllerCropRect

iphone - UIImagePickerController 在模拟器上工作,在设备上崩溃

objective-c - 在 UITableView 中的 UIImageView 中从网络加载图像

ios - 加快像素迭代

ios - 如何在 UIImages 的特定边上圆角?

ios - 在标签栏中的彩色 UIImage 周围绘制某种颜色的边框

app-store - 如何使用FaSTLane/Deliver更新有关贸易代表联系信息的元数据?

ios - 将 UIImagePickerController 的外观设置回默认值