Utilizing iOS CIFilter
, I’m making an attempt to recreate the glitch impact from Photoshop proven on this video:
https://www.youtube.com/watch?v=1Ibreg9T168
This is the unique picture:
Initially of the video, the individual firstly desaturates the picture to make it grayscale. Then creates a replica of that layer. Then disables the Pink channel on that layer. Then shifts it barely to the left to get this have a look at 55 second mark:
This ought to be doable simply with CIFilter
. I did the under:
if let picture = UIImage(named: "demo13"), let editted = applyGlitchEffect(to: picture) {
imageView.picture = editted
}
func applyGlitchEffect(to picture: UIImage) -> UIImage? {
guard let ciImage = CIImage(picture: picture) else { return nil }
let context = CIContext(choices: nil)
let grayscaleFilter = CIFilter(identify: "CIColorControls", parameters: [
kCIInputImageKey: ciImage,
kCIInputSaturationKey: 0.0
])
let noRedChannel = CIFilter(identify: "CIColorMatrix", parameters: [
kCIInputImageKey: grayscaleFilter?.outputImage as Any,
"inputRVector": CIVector(x: 0, y: 0, z: 0, w: 0)
])
let shifted = noRedChannel?.outputImage?.reworked(by: CGAffineTransform(translationX: -20, y: 0))
let blended = CIFilter(identify: "CIScreenBlendMode")
blended?.setValue(shifted, forKey: kCIInputImageKey)
blended?.setValue(grayscaleFilter?.outputImage as Any, forKey: kCIInputBackgroundImageKey)
if let finalOutput = blended?.outputImage, let cgImage = context.createCGImage(finalOutput, from: ciImage.extent) {
return UIImage(cgImage: cgImage)
}
return nil
}
This provides me the under outcome:
As you possibly can see, my result’s just like the one within the video at 55 second mark. Nevertheless, my picture has a bluish tint to it for some cause. Whereas the one within the video is grayscale with shifted reds and blacks on the edges.
I believe I is likely to be utilizing the incorrect mix mode or one thing. I did attempt a number of different mix modes however did not get related outcome.
I appeared up what mix mode Photoshop makes use of and in keeping with this:
https://helpx.adobe.com/photoshop/utilizing/blending-modes.html
the default is “Regular: Edits or paints every pixel to make it the outcome colour. That is the default mode.”
How can I recreate it? What am I doing incorrect?