// Let's try to generate the CGImage from the CIImage before creating a UIImage.
if let cgImage = CIContext(options: nil).createCGImage(filteredImage, from: filteredImage.extent) {
uiImage = UIImage(cgImage: cgImage)
} else {
uiImage = UIImage(ciImage: filteredImage, scale: 1.0, orientation: .up)
}
// Let's try to generate the CGImage from the CIImage before creating a UIImage.
if let cgImage = CIContext(options: nil).createCGImage(filteredImage, from: filteredImage.extent) {
uiImage = UIImage(cgImage: cgImage)
} else {
uiImage = UIImage(ciImage: filteredImage, scale: 1.0, orientation: .up)
}