我正在使用核心图像,我正在为我的图像应用CIFilter棕褐色调.我在viewDidLoad中运行一次过滤器,然后立即调用另一个再次添加过滤器的函数.出于某种原因,当我尝试访问输出图像时,应用程序崩溃并说输出图像为零.任何人都知道为什么会这样吗?
谢谢
import UIKit class ViewController: UIViewController { @IBOutlet weak var myimage: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. let image = CIImage(image: myimage.image) let filter = CIFilter(name: "CISepiaTone") filter.setDefaults() filter.setValue(image,forKey: kCIInputImageKey) myimage.image = UIImage(CIImage: filter.outputImage) self.reapplyFilter() } func reapplyFilter(){ let image = CIImage(image: myimage.image) let filter = CIFilter(name: "CISepiaTone") filter.setDefaults() filter.setVa lue(image,forKey: kCIInputImageKey) //ERROR HERE: fatal error: unexpectedly found nil while unwrapping an Optional value myimage.image = UIImage(CIImage: filter.outputImage) //ERROR } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }