从Image选择器中选择图像并尝试将PHAsset转换为UIImage图像后,png图像的透明度将会下降。 我尝试到处寻找,但没有找到任何相关信息。
func getAssetThumbnail(asset: PHAsset) -> UIImage {
let manager = PHImageManager.defaultManager()
let option = PHImageRequestOptions()
var thumbnail = UIImage()
option.synchronous = true
manager.requestImageForAsset(asset, targetSize: CGSize(width: 341.0, height: 182.0), contentMode: .AspectFit, options: option, resultHandler: {(result, info)->Void in
thumbnail = result!
})
return thumbnail
}
之前的图片
选择并将其设置为图像视图后
答案 0 :(得分:6)
使用PHImageRequestOptions.version = . Original
致电UIImage(data: data)
获取原始图片数据。然后,您可以从 func getThumbnail(asset: PHAsset) -> UIImage? {
var thumbnail: UIImage?
let manager = PHImageManager.defaultManager()
let options = PHImageRequestOptions()
options.version = .Original
options.synchronous = true
manager.requestImageDataForAsset(asset, options: options) { data, _, _, _ in
if let data = data {
thumbnail = UIImage(data: data)
}
}
return thumbnail
}
创建图像。
示例:
response.json()