ios - CIFilter won't apply filter at touch location -
i using code below apply image filter touch location set radius, filter being placed in wrong spot. x coordinate seems close, y coordinate reversed , 400+ pixels off touch. if move finger up, filter moves down , opposite. using kciinputcenterkey : civector parameter incorrectly? how place center of filter radius @ touch location?
override func touchesmoved(touches: set<uitouch>, withevent event: uievent?) { let filter = cifilter(name: "cipixellate")! let inputimage = ciimage(image: originalimage)! filter.setvalue(inputimage, forkey: kciinputimagekey) let fullpixellatedimage = filter.outputimage var maskimage: ciimage! let radialgradient = cifilter(name: "ciradialgradient", withinputparameters: [ "inputradius0" : 30, kciinputcenterkey : civector(x: (touches.first?.locationinview(self.view).x)!, y: (touches.first?.locationinview(self.view).y)!) ])! let radialgradientoutputimage = radialgradient.outputimage!.imagebycroppingtorect(inputimage.extent) if maskimage == nil { maskimage = radialgradientoutputimage } else { maskimage = cifilter(name: "cisourceovercompositing", withinputparameters: [ kciinputimagekey : radialgradientoutputimage, kciinputbackgroundimagekey : maskimage ])!.outputimage } let blendfilter = cifilter(name: "ciblendwithmask")! blendfilter.setvalue(fullpixellatedimage, forkey: kciinputimagekey) blendfilter.setvalue(inputimage, forkey: kciinputbackgroundimagekey) blendfilter.setvalue(maskimage, forkey: kciinputmaskimagekey) let blendoutputimage = blendfilter.outputimage! let blendcgimage = context.createcgimage(blendoutputimage, fromrect: blendoutputimage.extent) mainimageview.image = uiimage(cgimage: blendcgimage) }
Comments
Post a Comment