我正在使用Swift中的Core Image来编辑照片,但在保存照片时遇到了问题。我没有正确保存图片的方向。
当我从照片库获取图片时,我将其方向保存在UIImageOrientation变量中,但不知道如何在将编辑后的照片保存到照片库之前重新设置它。有什么想法吗?
保存方向:
将编辑后的照片保存到照片库中:
当我从照片库获取图片时,我将其方向保存在UIImageOrientation变量中,但不知道如何在将编辑后的照片保存到照片库之前重新设置它。有什么想法吗?
保存方向:
var orientation: UIImageOrientation = .Up
orientation = gotImage.imageOrientation
将编辑后的照片保存到照片库中:
@IBAction func savePhoto(sender: UIBarButtonItem) {
let originalImageSize = CIImage(image:gotImage)
filter.setValue(originalImageSize, forKey: kCIInputImageKey)
// 1
let imageToSave = filter.outputImage
// 2
let softwareContext = CIContext(options:[kCIContextUseSoftwareRenderer: true])
// 3
let cgimg = softwareContext.createCGImage(imageToSave, fromRect:imageToSave.extent())
// 4
let library = ALAssetsLibrary()
library.writeImageToSavedPhotosAlbum(cgimg,
metadata:imageToSave.properties(),
completionBlock:nil)
}
ALAssetsLibrary()
is deprecated in iOS 9, now you have to usePHPhotoLibrary
- Carlos.V