我正在画一个白色背景的画布,想要在画布周围画一个边框,但我无法实现。以下是我的代码:
canvas.width = image.width;
canvas.height = image.height;
var context = canvas.getContext('2d');
context.fillStyle = "black";
context.font = "50px Arial";
context.fillText(chartId, 0, 50);
context.drawImage(image, 0, 0);
context.globalCompositeOperation = "destination-over";
context.fillStyle = "#FFFFFF";
context.fillRect(0,0,canvas.width,canvas.height);//for white background
在此之后,我希望整个画布周围出现红色的边框。
canvas.style.border = '1px solid red';
只是在画布周围添加了一个 CSS 边框,而不是在画布上绘制它。在此处查看演示。 - blex