Reputation: 2747
I want to Implement background eraser functionality for my website. I am using canvas for that. I can put image data into canvas and get image data from canvas.
I have implement flood fill algorithm for remove color from particular place.
Here I tried it :
`http://jsfiddle.net/Mark_1998/boz43x87/`
After I googling too much, I found that black color not remove in this algorithm ,
As a rule of flood fill algorithm, If target color and replacement color are same then it will return function (no process further).
In My case, exact same doing here. In short :
Is there any way to match color with it's alpha value ?
If I replace new color (replacement color) with any other color , then it will not remove that color from image when target color is same as replacement color. e.g. i set replacement Color rgba(255,255,255,0) instead of rgba(0,0,0,0), then it will remove black color from image fine , but can't remove white color from image.
The only way for remove that color is finding distance of color with it's alpha value. but i don't know how to find that distance.
Please help me.
Upvotes: 2
Views: 123
Reputation: 945
You can change the alpha value with the globalAlpha property.
ctx.globalAlpha = 0;
Upvotes: 1