我已经用代码绘制了一个功能区:
var canvas = document.getElementById('draw-ribbon');
ctx = canvas.getContext("2d");
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(300, 0);
ctx.lineTo(260, 75);
ctx.lineTo(300, 150);
ctx.lineTo(0, 150);
ctx.closePath();
ctx.fill();
得到了这个:
在此之后我尝试了filltext()
但是没有工作我想实现这个目标:
答案 0 :(得分:1)
可能无效,因为文字颜色也是红色
var canvas = document.getElementById('myCanvas');
ctx = canvas.getContext("2d");
ctx.fillStyle = 'red';
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(300, 0);
ctx.lineTo(260, 75);
ctx.lineTo(300, 150);
ctx.lineTo(0, 150);
ctx.closePath();
ctx.fill();
ctx.font="30px Verdana";
ctx.fillStyle = 'white';
ctx.fillText("Text",50,80);