Affect the final alpha of combined draw calls

40 views Asked by At

I'd like to do something similar to this:

var p = context.image { ctx in
    ctx.cgContext.setAlpha(0.5)
    UIColor(hue: 0.2, saturation: 1, brightness: 1, alpha: 1).setFill()
    let p = UIBezierPath(roundedRect: CGRect(x: 100, y: 100, width: 200, height: 200), cornerRadius: 10)
    let q = UIBezierPath(roundedRect: CGRect(x: 150, y: 150, width: 200, height: 200), cornerRadius: 10)
    p.fill()
    q.fill()
}

Except, I want the ctx.cgContext.setAlpha(0.5) not to act as a multiplier for the individual fills but rather apply alpha to the combined rendered output of the two subsequent calls. It would be like rendering without the ctx.cgContext.setAlpha(0.5) and then taking the result and applying alpha to it (which creates a different image), sorta like the draw calls were on a pre-rendered layer.

I can't find a way to do this in Core Graphics without actually rendering an entirely separate image and then drawing that image into the context, which doesn't feel right. Perhaps there isn't a way?

0

There are 0 answers