【问题标题】:Swift picture metaData creation dateSwift 图片元数据创建日期
【发布时间】:2021-06-28 18:33:19
【问题描述】:

我正在尝试从 iOS 图片上传中使用 Swift 并获取图片 metaDate 示例创建日期,但我没有得到完整的信息:

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

}

我的快速代码:

        let imageData: Data = image.jpegData(compressionQuality: 1)!
        let source = CGImageSourceCreateWithData(imageData as CFData, nil)!
        let metadata = CGImageSourceCopyPropertiesAtIndex(source, 0, nil)!
       
        print(metadata)

而且我的图片有创建日期,因为我检查了另一个应用程序并看到了完整的元数据

【问题讨论】:

    标签: ios swift image


    【解决方案1】:

    以下是我在试验图像元数据时在游乐场创建的一个函数,它使用来自 URL 的文件,但如果您改用 CGImageSourceCreateWithData,它应该对您有用

    func createDate(for url: URL) -> String? {
        guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil),
              let properties = CGImageSourceCopyMetadataAtIndex(imageSource, 0, nil) else {
            return nil
        }
        let datePath = "xmp:CreateDate" as CFString
        return CGImageMetadataCopyStringValueWithPath(properties, nil, datePath) as String?
    }
    

    【讨论】:

    • 真的是返回图片创建日期吗?因为它看起来没有,对我来说我得到零
    • 对我来说,它在使用 jpeg 和 dng 图像文件进行测试时返回一个日期字符串。如果您尝试使用“exif:ColorSpace”会发生什么,因为您的示例数据中有这个?
    • 是的,我得到了 colorSpace 值
    • 然后代码工作,但你没有我使用的标签。也许在路径字符串中尝试 exif 而不是 xmp 或 DateTimeOriginal 而不是 CreateDate。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-25
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    相关资源
    最近更新 更多