UIImageView not showing transparency of PNG Images from UIImagePickerController

后端 未结 3 868
忘掉有多难
忘掉有多难 2020-12-07 02:21

I surely hope I am missing something because I do not understand why this is working the way it does. I have a PNG Image, which has a fully transparent background because I

3条回答
  •  孤城傲影
    2020-12-07 02:34

    Swift 3 version of answer by @Rob

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let URL = info[UIImagePickerControllerReferenceURL] as? NSURL {
            let result = PHAsset.fetchAssets(withALAssetURLs: [URL as URL], options: nil)
            if let asset:PHAsset = result.firstObject! as PHAsset {
                let manager = PHImageManager.default()
                manager.requestImageData(for: asset, options: nil) { imageData, dataUTI, orientation, info in
                    let fileURL = info!["PHImageFileURLKey"] as? NSURL
                    let filename = fileURL?.lastPathComponent;
    
                    // use imageData here
                }
            }
        }
    
        picker.dismiss(animated: true, completion: nil)
    
    }
    

提交回复
热议问题