<!DOCTYPE html>
<html>
<head>
  <title>Clear Text on Canvas</title>
</head>
<body>
  <canvas id="myCanvas" width="400" height="200" style="background-color: red;"></canvas>
  <script>
    var canvas = document.getElementById("myCanvas");
    var ctx = canvas.getContext("2d");

    ctx.font = "30px Arial";
    ctx.fillStyle = "white";
    ctx.fillText("Hello World", 50, 50);

    // Clear text
    ctx.fillStyle = "red";
    ctx.fillRect(50, 30, 200, 50);
  </script>
</body>
</html>
清除Canvas上的文字,保留红色背景 - HTML代码示例

原文地址: https://www.cveoy.top/t/topic/pPTX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录