When applying a filter to a UIImage the result is upside down

折月煮酒 提交于 2019-12-08 07:09:15

问题


This is really annoying me. When I convert a UIImage to a CIImage, apply a filter then convert back the image is upside down (for landscape) or rotated anticlockwise 90 degrees (for portrait).

var image:UIImage?
var index:Int?

@IBOutlet weak var photo: UIImageView!

@IBAction func editImage(sender: UIBarButtonItem) {
    println("editImage")
    let beginImage = CIImage(image: self.image)
    let filter = CIFilter(name: "CISepiaTone")
    filter.setValue(beginImage, forKey: kCIInputImageKey)
    filter.setValue(0.8, forKey: kCIInputIntensityKey)
    let newImage = UIImage(CIImage: filter.outputImage)
    self.photo.image = newImage
}

回答1:


Set the image orientation and scale of the filtered image back to the original values:

let newImage = UIImage(CIImage:filter.outputImage, scale:self.image.scale, orientation:self.image.imageOrientation)


来源:https://stackoverflow.com/questions/26745026/when-applying-a-filter-to-a-uiimage-the-result-is-upside-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!