简体   繁体   English

如何在HTML5画布中添加背景图像数据

[英]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);

If you are using only a single color, what about using fillRect instead? 如果您只使用一种颜色,那么使用fillRect呢?

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

~Cheers 〜干杯

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM