7

I ma working on app that has brush tool. I need create brush like in Instagramenter image description here.

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()

But effect isn't so good. enter image description here

So I what draw such brush using next algorithm:

  1. Draw colored smooth fill circles with 1px step, rad 20 px.
  2. 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)

Victor.V
  • 177
  • 1
  • 9
  • Hey Victor.V -- by any chance did you resolve this issue? Currently trying to do something similar and running into some rendering problems (overlapping shadows, etc) -- thanks! – Yoseob Lee Jul 19 '19 at 19:12
  • Hey guys, did you get any solution for this problem? – pushpank Apr 17 '20 at 15:37

0 Answers0