Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

canvas fillStyle in interval with transparent/opacity

Tags:

This small code clear old canvas data in interval:

// start interval ctx.save();     ctx.fillStyle = "rgba(0, 0, 0, 0.2)";     ctx.fillRect(0, 0, ctx.width, ctx.height); ctx.restore(); //some draw code for new graph ... //end interval 

My work area become black, because i set black as fill color ( rgba(0, 0, 0, .2) ), but I need a transparent background, not black.

I tried use globalAlpha and imagePutData but i failed.

How i can do this?

like image 625
user951114 Avatar asked Sep 18 '11 10:09

user951114


2 Answers

I think this will resolve your issue

ctx.fillStyle = "rgba(255, 255, 255, 0.5)"; 
like image 168
Mubashar Shahzad Avatar answered Sep 22 '22 18:09

Mubashar Shahzad


Using an rgba(0,0,0,.2) fillStyle and fillRect() works for me on both chrome and firefox - it paints a semi-transparent black fill. Check to make sure you're not doing something else that's causing a fully opaque paint of some sort.

like image 44
broofa Avatar answered Sep 20 '22 18:09

broofa