答案 0 :(得分:2)
答案 1 :(得分:2)
我会使用ctx.globalCompositeOperation = "source-atop"
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
let cw = canvas.width = 400;
let ch = canvas.height = 110;
ctx.fillStyle = "#ccc";
ctx.beginPath();
ctx.fillRect(100,25,200,60);
ctx.globalCompositeOperation = "source-atop"
ctx.font="2em Verdana";
ctx.fillStyle = "#f00";
ctx.fillText("This is some text",110,65);
canvas{border:1px solid;}
<canvas id="canvas"></canvas>