다음 방법 중 하나를 사용하여 QR filter effect
을 사용하면 coreImage
을 사용할 수 있습니다.
출력 :
방법 1 :Using Custom Filter
Step1:
는 다음과 같은 custom kernel
에 별도의 class
을 만듭니다.
class CustomFilter: CIFilter {
var inputImage: CIImage?
override public var outputImage: CIImage! {
get {
if let inputImage = self.inputImage {
let args = [inputImage as AnyObject]
return createCustomKernel().apply(withExtent: inputImage.extent, arguments: args)
} else {
return nil
}
}
}
}
func createCustomKernel() -> CIColorKernel {
let kernelString =
"kernel vec4 chromaKey(__sample s) { \n" +
" vec4 newPixel = s.rgba;" +
" newPixel[0] = 0.0;" +
" newPixel[2] = newPixel[2]/2.0;" +
" return newPixel;\n" +
"}"
return CIColorKernel(string: kernelString)!
}
귀하의 ViewController
에 사용자 정의 필터를 아래와 같이 선언 할 수 있습니다.
var context = CIContext(options: nil)
func customQRFilter() {
let myInvertFilter = CIFilter(name: "CIColorInvert")
myInvertFilter!.setValue(CIImage(image: imageView.image!), forKey: kCIInputImageKey)
let output = myInvertFilter!.outputImage
let filter = CustomFilter()
filter.setValue(output, forKey: kCIInputImageKey)
// Get the filtered output image and return it
let outputImage = filter.outputImage!
let cgimg = context.createCGImage(outputImage,from: output!.extent)
let processedImage = UIImage(cgImage: cgimg!)
imageView.image = processedImage
}
방법 2 :CIColorMatrix
필터를 사용하여.
func colorMatrixFilter() {
let myInvertFilter = CIFilter(name: "CIColorInvert")
myInvertFilter!.setValue(CIImage(image: imageView.image!), forKey: kCIInputImageKey)
let output = myInvertFilter!.outputImage
let filter = CIFilter(name: "CIColorMatrix")
filter?.setDefaults()
filter?.setValue(output, forKey: kCIInputImageKey)
let r = CGFloat(0.0)
let g = CGFloat(0.9)
let b = CGFloat(0.416)
filter?.setValue(CIVector(x: r, y: 0, z: 0, w: 0), forKey: "inputRVector")
filter?.setValue(CIVector(x: 0, y: g, z: 0, w: 0), forKey: "inputGVector")
filter?.setValue(CIVector(x: 0, y: 0, z: b, w: 0), forKey: "inputBVector")
filter?.setValue(CIVector(x: 0, y: 0, z: 0, w: 1), forKey: "inputAVector")
let outputs = filter?.outputImage
let cgimg = context.createCGImage(outputs!,from: output!.extent)
let processedImage = UIImage(cgImage: cgimg!)
imageView2.image = processedImage
}
참고 : I 조언 당신이 원하는 RGB value of any colour
을 선택하는 colour Picker tool
를 사용합니다.