How do I draw lines with alpha < 1 in quartz 2d

前端 未结 4 1415
执笔经年
执笔经年 2020-12-20 01:12

No doubt this might be a duplicate question but I am not able to get proper solution from any post here. So I am posting this as new post with a hope that I get some solutio

4条回答
  •  执念已碎
    2020-12-20 01:38

    Duplicate of In CoreGraphics drawing how can I keep the point of overlap from being darker than the rest of the line?

    The trick is to have the brush stroke in its own buffer, where you can clip the alpha properly before blending the whole thing with the background.

    Here's one way to do that: Create 2 views, one for the background, another one for the lines. Draw the lines in the top view with an alpha of 1! Then set the alpha of this whole foreground view to 0.5 (or whatever value you want to use).

    [topView setAlpha:0.5];
    

    That will prevent a semi-transparent brush stroke from intensifying itself. But what about 2 different brush strokes that cross each other (like in your example). Do you want that intersection to be more intense? If so, then you need to create a new view for every brush stroke. To prevent memory overflow for having too many views, you then need to blend the previous top view(s) with the background.

提交回复
热议问题