swift - Converting UIImage to CIImage Returns nil -


i'm trying convert uiimage imageview ciimage purpose of filtering it. however, cannot ciimage have value.

in simplest form, here's trying:

let ciinput = ciimage(image: imageview.image!) 

but ciinput nil. have tried

let ciinput = ciimage(cgimage: imageview.image!.cgimage) 

but returns nil.

(imageview.image not nil, imageview.image!.cgimage , imageview.image!.ciimage both nil)

i need convert uiimage imageview valid ciimage. appreciated, thanks!

edit: here full function code

func makewhitetransparent(imageview: uiimageview) {      let invertfilter = cifilter(name: "cicolorinvert")     let cicontext = cicontext(options: nil)      let ciinput = ciimage(image: imageview.image!) //this nil     invertfilter?.setvalue(ciinput, forkey: "inputimage")      let cioutput = invertfilter?.outputimage     let cgimage = cicontext.createcgimage(cioutput!, from: (cioutput?.extent)!)      imageview.image = uiimage(cgimage: cgimage!) } 

when running function, fatal unwrapping nil error on last line. using debugger, discovered ciinput nil, should not be.

edit 2: image on imageview before calling makewhitetransparent qr code generated function:

func generateqrcode(from string: string) -> uiimage? {     let data = string.data(using: string.encoding.ascii)      if let filter = cifilter(name: "ciqrcodegenerator") {         filter.setvalue(data, forkey: "inputmessage")          let transform = cgaffinetransform(scalex: 12, y: 12)          if let output = filter.outputimage?.applying(transform) {             return uiimage(ciimage: output)         }     }      return nil } 

so problem in qr code generation. code returned uiimage ciimage without utilizing cgcontext return uiimage. here corrected qr code function fixed issue.

func generateqrcode(from string: string) -> uiimage? {     let data = string.data(using: string.encoding.ascii)      if let filter = cifilter(name: "ciqrcodegenerator") {         filter.setvalue(data, forkey: "inputmessage")          let transform = cgaffinetransform(scalex: 12, y: 12)          if let output = filter.outputimage?.applying(transform) {             let context = cicontext()             let cgimage = context.createcgimage(output, from: output.extent)             return uiimage(cgimage: cgimage!)         }     }      return nil } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -