我正在制作照片编辑应用程序.
@H_404_16@func blackWhiteImage(image: UIImage) -> Data { print("Starting black & white") let orgImg = CIImage(image: image) let bnwImg = orgImg?.applyingFilter("CIColorControls",withInputParameters: [kCIInputSaturationKey:0.0]) let outputImage = UIImage(ciImage: bnwImg!) print("Black & white complete") return UIImagePNGRepresentation(outputImage)! }
fatal error: unexpectedly found nil while unwrapping an Optional value
我的代码略有不同,但是当它到达UIImagePNG / JPEGRepresentation(xx)部分时它仍然会中断.
有没有办法从CIImage中获取PNG或JPEG数据,以便在图像视图/ UIImage中使用?