Post

Replies

Boosts

Views

Activity

Reply to QR Code Generator (CIFilter) colours for light/dark mode ?
Thanks for the code. I had to modify the imageAsset?.register check to the following as I could not use @Environment(.colorScheme) because the Struct was not a View, as in other part of the my code, which was in SwiftUI: var osTheme: UIUserInterfaceStyle { return UIScreen.main.traitCollection.userInterfaceStyle } qrImage = osTheme == .light ? lightImage : darkImage But otherwise it worked. The code that I found in the mean time was compiling but didn't work, it was a SO example using the "CIFalseColor" filter: var qrImage = UIImage(systemName: "xmark.circle") ?? UIImage()         let data = Data(text.utf8)         let filter = CIFilter.qrCodeGenerator()         filter.setValue(data, forKey: "inputMessage")         let transform = CGAffineTransform(scaleX: 2, y: 2)         if let outputImage = filter.outputImage?.transformed(by: transform) {             if let image = context.createCGImage(                 outputImage,                 from: outputImage.extent) {                 qrImage = UIImage(cgImage: image)                 let colorParameters = [                     "inputColor0": CIColor(color: UIColor.black), // Foreground                     "inputColor1": CIColor(color: UIColor.green) // Background]                 let colored = outputImage.applyingFilter("CIFalseColor", parameters: colorParameters)                 qrImage = UIImage(ciImage: colored)             }         }         return qrImage Anyway, it does work now. Many thanks !
Mar ’22
Reply to Pixelate transition in SpriteKit using CIFilter
I have managed to simulate Apple's Core Image "CIPixelate" filter working with a transition. Prepare by trawling all SKNodes on the scene and moving them to an SKEffectNode, which allows the filter to be applied to all its children in one go. Then place each iteration from a loop e.g. 1-20 (sweetspot) in a DispatchQueue with enough time for the pixelation effect to seem real. //ITERATE OVER EACH PIXELATION REQUEST TO CREATE AN ANIMATION for num in 1...20 { let seconds = 0.3 + 0.1 * Double(num) DispatchQueue.main.asyncAfter(deadline: .now() + seconds) { effectNode.filter = CIFilter(name : "CIPixellate", parameters : [kCIInputScaleKey: (num)]) } } Finish by calling the scene transition function after the filter has had enough time to complete (I probably should use a dependency operation) gives the desired impression. ref : https://github.com/rHockWorks/PixelationTransition/
Jul ’21