0

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);
whostolemyhat
  • 3,107
  • 4
  • 34
  • 50
Shanky
  • 201
  • 1
  • 4
  • 16

2 Answers2

2

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

Christoph Martens
  • 277
  • 1
  • 2
  • 10
0

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);
Community
  • 1
  • 1
Maurice
  • 27,582
  • 5
  • 49
  • 62