小编Adr*_*ina的帖子

可选类型“UIImage?”的值 没有打开

我正在尝试创建一个简单的过滤器应用程序,在按下按钮时过滤显示的图像。

 @IBAction func applyFilter(sender: AnyObject) {

    // Create an image to filter
    let inputImage = CIImage(image: photoImageView.image)

    // Create a random color to pass to a filter
    let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314)) / 100)]

    // Apply a filter to the image
    let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust", withInputParameters: randomColor)

    // Render the filtered image
    let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent())

    // Reflect the change back in the interface
    photoImageView.image = UIImage(CGImage: renderedImage)

}
Run Code Online (Sandbox Code Playgroud)

我不断收到错误:

可选类型“UIImage?”的值 没有解开。

我在这里做错了什么?我是 Swift 初学者。

optional uiimage ios swift

5
推荐指数
1
解决办法
8396
查看次数

标签 统计

ios ×1

optional ×1

swift ×1

uiimage ×1