Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

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

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 solution.

I my drawing app I want to give a feature of opacity for lines to be drawn. But when I assign alpha to color, I am getting overlapped points in between the line.

Some where I found that drawing in two views solves this issue, but I was not able to understand the logic behind that.

enter image description here

I am using normal quartz 2d code to draw line on touch events.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.5k users

...