【问题标题】:Stroke at coordinates on HTML canvas with Javascript [duplicate]用JavaScript与HTML画布上的坐标中风[复制]
【发布时间】:2021-03-19 04:32:13
【问题描述】:

我正在尝试在画布的特定位置描边 sv​​g 路径,但我不确定如何指示描边路径的坐标。我怎样才能做到这一点?到目前为止,我有以下代码。

var path = new Path2D(//path string here);
ctx.fillStyle = '#000';
ctx.strokeStyle = '#000';
ctx.stroke(path);
ctx.fill(path);

【问题讨论】:

    标签: javascript svg html5-canvas


    【解决方案1】:

    一些搜索为我回答了这个问题:How to position Path2D SVG element in canvas?

    感谢 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-02
      • 2020-10-02
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-24
      相关资源
      最近更新 更多