我正在尝试检索使用以下方法保存的图像:
let pngData = UIImagePNGRepresentation(image)
let finalPath = filePath() // This method just create the path to save to.
saveImage(pngData, filePath: finalPath)
稍后我想检索这些数据并设置 UIButton 的 UIImageView。但是,当我使用以下代码时,它只会显示一个完全蓝色的图像。
这是代码:
let filePath = tempCard?.frontPhoto
let imgData = UIImage(contentsOfFile: filePath!)frontPhotoButton.setImage(imgData, forState: .Normal)
frontPhotoButton.setImage(imgData, forState: .Normal)
我不确定为什么这只是显示一个蓝色按钮。
编辑:
我也试过:
let filePath = tempCard?.frontPhoto
let imageData = NSData(contentsOfFile: filePath!
let image = UIImage(data: imageData!)
frontPhotoButton.setImage(image, forState: .Normal)
结果相同。