4
我目前正在製作照片編輯應用程序。CIImage的PNG/JPEG圖像始終返回零
如果照片是由用戶選擇,則自動轉換成黑色,並使用白色此代碼:
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?
其他任何方法都沒有詳細介紹應該使用什麼代碼。
一個CIImage是不是圖像。你必須渲染它才能獲得圖像。 – matt
重複的http://stackoverflow.com/questions/40319229/uiimagepng-representation-from-avfoundation-returns-nil和其他許多人 – matt