[英]unable to make background colored for a rectange on html5 canvas
我添加以下行是为了使边框的颜色和背景的绿色变为矩形,但没有成功:
context.fillStyle = 'green';
context.fill();
context.strokeStyle = 'green';
context.stroke();
这是我在JSFIDDLE中的代码: https ://jsfiddle.net/f5z8qtcp/1/
如何在背景中使绿色矩形也着色...在创建灰色矩形时一定是这样,我只想对结果着色(边框已经着色为绿色)。
谢谢。
使用fillRect
函数:
function drawAll(){
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.lineWidth=1;
ctx.strokeStyle='green';
ctx.fillStyle = 'green';
for(var i=0;i<rects.length;i++){
var r=rects[i];
ctx.strokeRect(r.left,r.top,r.right-r.left,r.bottom-r.top);
ctx.fillRect(r.left,r.top,r.right-r.left,r.bottom-r.top);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.