【发布时间】:2018-10-16 12:04:04
【问题描述】:
我一直在尝试水平翻转UIImage 图像,以便将其保存在我的相册中,一切正常,我可以将图像保存到相册,但图像虽然在我的应用程序中出现翻转未在相册中另存为翻转。我正在使用以下代码来翻转图像:
myImage?.withHorizontallyFlippedOrientation()
注意:我不是要翻转UIImageView,而是要翻转图像并将其保存到一个新的图像变量中,并将该图像变量中的图像分配给UIImageView。
完整的 IBA 操作代码:
@IBAction func horizontalFlipBtnPressed(_ sender: Any) {
if myImageView.image != nil{
let image = myImageView.image
tempImage.append((image?.withHorizontallyFlippedOrientation())!)
myImageView.image = tempImage.last
}
else{
print ("there is no image selected")
}
}
相册保存代码:
if myImageView.image != nil{
var image = myImageView.image
let imageData = image!.pngData()
let compressedImage = UIImage(data: imageData!)
UIImageWriteToSavedPhotosAlbum(compressedImage!, nil, nil, nil)
let alert = UIAlertController(title: "Saved", message: "Your image has been saved!", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil)
alert.addAction(okAction)
self.present(alert, animated: true,completion: nil)
}
【问题讨论】:
-
你用什么代码保存图片?
-
我已经在上面添加了它的代码(编辑后)。