IOS 从相册里拿到照片的格式转换

iPhone手机有一些实况图,全景图等,如果直接去文件后缀,安卓或者web是不支持的,我们的需求就是把这些格式全部都转成任何的格式,JPEG就可以,简单的来写,就是如下代码:

import MobileCoreServices

    public func getOriginalPhotoData(_ asset: PHAsset?, completion: @escaping (_ data: Data?, _ info: [AnyHashable: Any]?, _ isDegraded: Bool?) -> (Swift.Void)) {

        let option = PHImageRequestOptions()
        option.deliveryMode = .highQualityFormat
        option.isSynchronous = true
        option.isNetworkAccessAllowed = true
        let fileName: String? = asset!.value(forKeyPath: "filename") as? String
        if let fileName = fileName, fileName.hasSuffix("GIF") {
            option.version = .original
        }

        PHImageManager.default().requestImageData(for: asset!, options: option) { (imageData, dataUTI, _/*orientation*/, info) in

            guard let dataUTI = dataUTI else { return }

你可能感兴趣的:(iOS,Swift,iOS,相册图片后缀)