简体   繁体   中英

BSImagePicker all Images blurred

I'm using BSImagePicker instead of UIImagePicker to enable multi select. I'm using following code for this:

    let bsImagePicker = BSImagePickerViewController()
    bsImagePicker.maxNumberOfSelections = 4

    self.bs_presentImagePickerController(bsImagePicker, animated: true, select: { (asset : PHAsset) in

    }, deselect: { (asset : PHAsset) in

    }, cancel: { (assets : [PHAsset]) in

    }, finish: { (assets : [PHAsset]) in

        for asset in assets {

            self.selectedAssets.append(asset)

            self.convertAssetsToImage()
        }

    }, completion: nil)

And for converting the PHAsset to an image I'm using this code:

func convertAssetsToImage() {

    for asset in selectedAssets {

        let manager = PHImageManager.default()
        let option = PHImageRequestOptions()
        var thumbnail = UIImage()
        option.isSynchronous = true

        manager.requestImage(for: asset, targetSize: CGSize(width: 340, height: 365), contentMode: .aspectFit, options: option, resultHandler: {(result, info) -> Void in

            thumbnail = result!
        })

        self.selectedPhotos.append(thumbnail)
    }

    DispatchQueue.main.async {

        self.imageViewImage.animationImages = self.selectedPhotos
        self.imageViewImage.animationDuration = 5.0
        self.imageViewImage.startAnimating()
    }
}

But all images are blurred. If the ImagePicker is shown, all images are slightly blurred and after selection the image is still blurred.

Thats an image of selection Screen:

选择画面

Thats an Image of the selected Image:

图像模糊

And for example, this is an image if I'm using an UIImagePicker:

在此处输入图片说明

You can add these two PHImageRequestOptions to tell photos to provide a high-quality image (possibly sacrificing speed).

option.deliveryMode = .highQualityFormat
option.resizeMode = .exact

100% worked for me :)

                   let option = PHImageRequestOptions()
                    option.deliveryMode = .highQualityFormat
                    option.resizeMode = .exact

                    PHImageManager.default().requestImage(for: asset, targetSize: PHImageManagerMaximumSize, contentMode: .aspectFit, options: option) { (image, info) in
                        // Do something with image
                       
                    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM