我正在尝试在画布的特定位置上描边 svg 路径,但我不确定如何指示描边路径的坐标。我怎样才能做到这一点?到目前为止,我有以下代码。
var path = new Path2D(//path string here);
ctx.fillStyle = '#000';
ctx.strokeStyle = '#000';
ctx.stroke(path);
ctx.fill(path);
我正在尝试在画布的特定位置上描边 svg 路径,但我不确定如何指示描边路径的坐标。我怎样才能做到这一点?到目前为止,我有以下代码。
var path = new Path2D(//path string here);
ctx.fillStyle = '#000';
ctx.strokeStyle = '#000';
ctx.stroke(path);
ctx.fill(path);
一些搜索为我回答了这个问题:如何在画布中定位 Path2D SVG 元素?
感谢 Blindman67,我可以将位置翻译如下。
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
let p = new Path2D('M10 10 h 80 v 80 h -80 Z');
ctx.translate(100, 100);
ctx.fill(p);