I ma working on app that has brush tool. I need create brush like in Instagram.
Currently I am using Shadow to create such glow effect. But I can't set such shadow effect.
let startPoint = convertToOutput(firstPoint), endPoint = convertToOutput(secondPoint)
UIGraphicsBeginImageContextWithOptions(self.outputCanvasSize, false, 1.0)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.setStrokeColor(color.cgColor)
context?.setShadow(offset: CGSize(width:0, height: 0), blur: 20, color: color.cgColor)
context?.setLineJoin(.round)
context?.setLineCap(.round)
context?.setLineWidth(brush.radius * 2)
context?.move(to: startPoint)
context?.addLine(to: endPoint)
context?.drawPath(using: .stroke)
glowOverlayCanvas.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
So I what draw such brush using next algorithm:
- Draw colored smooth fill circles with 1px step, rad 20 px.
- Then draw white fill circles foreground, without smooth, rad 5 px.
I have a problem with blend mode, because if I use .normal, smooth effect disappear - alpha channel accumulate (few circles crossing)
How to implement the following blend mode
Rrgb = Srgb
Ra = MAX(Da, Sa)