Is there a way to draw on an HTML canvas
such that the resulting image is transparent?
I know you can set globalAlpha
, but that will only affect how subsequent drawing operations work: setting globalAlpha=.5
, then drawing black on red results in a dark red, not a transparent black.
I know you can canvas.fillStyle='rgba(0,0,0,0.5)'
, but again, that will only affect the drawing operation, not the color that is drawn (see this fiddle).
I find this incredibly counter-intuitive.
When I draw in rgba(0, 0, 0, 0.5)
at a point where the canvas was previously red, I want the canvas to be gray at that point and transparent. The reason I want this is that I want to upload the image and get a partially transparent image.
Is there any way to do that?