跳到主要内容

stroke

2023年08月11日
柏拉文
越努力,越幸运

一、认识


ctx.stroke()Canvas 2D API 使用非零环绕规则,根据当前的画线样式,绘制当前或已经存在的路径的方法。

二、语法


ctx.stroke();
ctx.stroke(path);
  • path: 绘制的路径Path2D

三、场景


3.1 填充矩形轮廓

<canvas id="canvas"></canvas>

<script>
const canvas = document.querySelector("#canvas");
const ctx = canvas.getContext('2d');

ctx.fillStyle = 'green';
ctx.rect(0,0,200,100);
ctx.stroke();
</script>