iOS 用photokit读取metaData 数据变少的问题

ALAsset读取metaData的文章一搜一大把,photokit也有不少,但是,没有一篇文章提到数据缺失的问题

NSURL *fileUrl = [[NSBundle mainBundle] URLForResource:@"name" withExtension:@"JPG"];
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((CFURLRef)fileUrl, NULL);
CFDictionaryRef imageInfo = CGImageSourceCopyPropertiesAtIndex(imageSource, 0,NULL);
NSLog(@"%@",imageInfo);

把图片拉倒项目里 可以得到完整的数据,但是 如果从相册里拿到图片就不行了,下面做一个对比
下面这个数据是完整的数据

ColorModel = RGB;
    DPIHeight = 72;
    DPIWidth = 72;
    Depth = 8;
    Orientation = 1;
    PixelHeight = 3000;
    PixelWidth = 4000;
    ProfileName = "sRGB IEC61966-2.1";
    "{Exif}" =     {
        ApertureValue = "2.97";
        ColorSpace = 1;
        ComponentsConfiguration =         (
            0,
            3,
            2,
            1
        );
        CompressedBitsPerPixel = "3.004617414248021";
        Contrast = 0;
        CustomRendered = 0;
        DateTimeDigitized = "2018:04:01 00:00:00";
        DateTimeOriginal = "2018:04:01 15:00:20";
        DigitalZoomRatio = 0;
        ExifVersion =         (
            2,
            3
        );
        ExposureBiasValue = 1;
        ExposureIndex = 0;
        ExposureMode = 0;
        ExposureProgram = 2;
        ExposureTime = "0.007561999464110274";
        FNumber = "2.8";
        FileSource = 3;
        Flash = 32;
        FlashPixVersion =         (
            0,
            1
        );
        FocalLenIn35mmFilm = 20;
        FocalLength = "3.61";
        GainControl = 0;
        ISOSpeedRatings =         (
            100
        );
        LightSource = 0;
        MaxApertureValue = "2.97";
        MeteringMode = 2;
        PixelXDimension = 4000;
        PixelYDimension = 3000;
        Saturation = 0;
        SceneCaptureType = 0;
        SceneType = 0;
        Sharpness = 0;
        ShutterSpeedValue = "7.046";
        SubjectDistRange = 0;
        SubjectDistance = 0;
        WhiteBalance = 0;
    };
    "{GPS}" =     {
        Altitude = "92.46700507614213";
        AltitudeRef = 0;
        GPSVersion =         (
            0,
            0,
            0,
            0
        );
        Latitude = "29.18146666666667";
        LatitudeRef = N;
        Longitude = "112.6311333333333";
        LongitudeRef = E;
    };
    "{IPTC}" =     {
        "Caption/Abstract" = "DCIM\\100MEDIA\\DJI_0002.JPG";
        DateCreated = 20180401;
        DigitalCreationDate = 20180401;
        TimeCreated = 150020;
    };
    "{TIFF}" =     {
        DateTime = "2018:04:01 15:00:20";
        ImageDescription = "DCIM\\100MEDIA\\DJI_0002.JPG";
        Make = DJI;
        Model = FC330;
        Orientation = 1;
        ResolutionUnit = 2;
        Software = "v01.19.5266";
        XResolution = 72;
        YResolution = 72;
    };
}

从系统相册里拿的图片

[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
     NSData *imageData = UIImageJPEGRepresentation(result, 0.5);
     CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
     CFDictionaryRef imageInfo = CGImageSourceCopyPropertiesAtIndex(imageSource, 0,NULL);
     NSLog(@"%@",imageInfo);           
}];

得到的数据

ColorModel = RGB;
    Depth = 8;
    Orientation = 1;
    PixelHeight = 1000;
    PixelWidth = 1334;
    ProfileName = "sRGB IEC61966-2.1";
    "{Exif}" =     {
        ColorSpace = 1;
        PixelXDimension = 1334;
        PixelYDimension = 1000;
    };
    "{JFIF}" =     {
        DensityUnit = 0;
        JFIFVersion =         (
            1,
            0,
            1
        );
        XDensity = 72;
        YDensity = 72;
    };
    "{TIFF}" =     {
        Orientation = 1;
    };

少了这么多,GPS可以从asset.location里看得到
但是其他的信息也少了很多,搜了半天也没搜到,只能求助万能的Stack Overflow了,最后得到方法

//得到的PHAsset对象asset
[assett requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
    CIImage *fullImage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
    NSLog(@"%@",fullImage.properties);
}];

使用CIImage接收 ,而CIImage是什么呢
CIImage 包含了创建图片的所有必要的数据,但其本身没有渲染成图片,它代表的是图像数据或者生成图像数据的流程(如滤镜);(网上搜的)
emmmmmmm..........反正终于成功了,至于为什么缺失,我也不知道,但用CIImage接收,才是正确的方法。

你可能感兴趣的:(iOS 用photokit读取metaData 数据变少的问题)