Shanky
Shanky

Reputation: 203

How to add background image data in HTML5 canvas

I want to fill image data with white background. How can I add white background data with image data.

I'm using the following scenario:-

var imageData = shapesContext.getImageData(x,y,width,height);

context.putImageData(imageData,x,y);

Upvotes: 0

Views: 799

Answers (2)

Christoph Martens
Christoph Martens

Reputation: 277

If you are using only a single color, what about using fillRect instead?

context.fillStyle="white";
context.fillRect(0,0,canvas.width,canvas.height);

~Cheers

Upvotes: 2

Maurice
Maurice

Reputation: 27632

See this question for more details.

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");

var c2=document.getElementById("myCanvas2");
var ctx2=c2.getContext("2d");

ctx.strokeRect(5,5,25,15);

ctx2.drawImage(c, 10, 10);

Upvotes: 0

Related Questions