BSImagePicker所有图像模糊

时间:2018-06-29 11:44:56

标签: ios uiimageview uiimagepickercontroller

我正在使用BSImagePicker而不是UIImagePicker来启用多选。 我为此使用以下代码:

    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)

为了将PHAsset转换为图像,我正在使用以下代码:

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()
    }
}

但是所有图像模糊。如果显示了ImagePicker,则所有图像都会稍微模糊,选择后图像仍会模糊。

那是选择屏幕的图像:

Selection Screen

那是所选图像的图像:

Blurred Image

例如,如果我使用的是UIImagePicker,则这是一张图片:

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以添加这两个PHImageRequestOptions来告诉照片提供高质量的图像(可能会牺牲速度)。

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

答案 1 :(得分:0)

100%为我工作:)

                   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
                       
                    }