Android Question How to draw transparent (alpha) line without buildup?

Dave O

Active Member
Licensed User
Hi all,

Short version:
Is there a way to draw a transparent line so that it doesn't overlap/build up when drawn over itself? (That is, so that I can draw an alpha=50 line and draw over it again and it's still alpha=50 (instead of getting darker at the intersections)?

Longer version:
I'm drawing a semi-transparent line (e.g. yellow, alpha = 50) based on touch events, and that works well, except that I'm drawing a line from touch point to touch point, with a circle at each junction to keep the line "solid" with no ugly elbows.

This works fine for opaque lines, but for transparent lines, I get an ugly overlap because the alpha is cumulative.

Ideally, I'd like to draw the line so that its alpha is always 50, no matter how many times I draw over it.

Is there some kind of blend mode (or other graphics voodoo) that would help?

Or perhaps I have to draw the line opaque, but wrapped somehow inside a transparent drawable?

OK, now my brain hurts... :)
 

Dave O

Active Member
Licensed User
Yes, I'm drawing lines on a canvas assigned to a panel.

My typical use for alpha drawing is to be a semi-transparent highlighter drawing over other (usually black) shapes previously drawn on the same canvas.

Attached is an example showing the yellow alpha pen drawing over a black shape on the left, then by itself on the right. Ideally, the yellow would be smooth (all alpha 50) instead of blotchy because of the overlapping of the line segments.
 

Attachments

Dave O

Active Member
Licensed User
Yes, I could, but I'm not sure how that would change the ultimate rendering of the alpha pen.

Or do you mean drawing the yellow as opaque (which makes it all the same color value because alpha is maxed out), and making that whole layer somehow alpha-transparent?
 

Dave O

Active Member
Licensed User
@thedesolatesoul : Well, I'm already using the ABExtDrawing library to draw a transparent rounded rectangle, so it should be easy for me to play around with the Porter-Duff modes to see if any of them do what I want. Kind of like the first time I used Photoshop and spent an hour just playing with the drawing modes. :)
 
Top