<bdo id='O9WWi'></bdo><ul id='O9WWi'></ul>
  • <small id='O9WWi'></small><noframes id='O9WWi'>

      <legend id='O9WWi'><style id='O9WWi'><dir id='O9WWi'><q id='O9WWi'></q></dir></style></legend>
    1. <i id='O9WWi'><tr id='O9WWi'><dt id='O9WWi'><q id='O9WWi'><span id='O9WWi'><b id='O9WWi'><form id='O9WWi'><ins id='O9WWi'></ins><ul id='O9WWi'></ul><sub id='O9WWi'></sub></form><legend id='O9WWi'></legend><bdo id='O9WWi'><pre id='O9WWi'><center id='O9WWi'></center></pre></bdo></b><th id='O9WWi'></th></span></q></dt></tr></i><div id='O9WWi'><tfoot id='O9WWi'></tfoot><dl id='O9WWi'><fieldset id='O9WWi'></fieldset></dl></div>

      1. <tfoot id='O9WWi'></tfoot>
      2. 如何在画布中定位 Path2D SVG 元素?

        How to position Path2D SVG element in canvas?(如何在画布中定位 Path2D SVG 元素?)
        • <bdo id='HIKkb'></bdo><ul id='HIKkb'></ul>

              <legend id='HIKkb'><style id='HIKkb'><dir id='HIKkb'><q id='HIKkb'></q></dir></style></legend>
              <i id='HIKkb'><tr id='HIKkb'><dt id='HIKkb'><q id='HIKkb'><span id='HIKkb'><b id='HIKkb'><form id='HIKkb'><ins id='HIKkb'></ins><ul id='HIKkb'></ul><sub id='HIKkb'></sub></form><legend id='HIKkb'></legend><bdo id='HIKkb'><pre id='HIKkb'><center id='HIKkb'></center></pre></bdo></b><th id='HIKkb'></th></span></q></dt></tr></i><div id='HIKkb'><tfoot id='HIKkb'></tfoot><dl id='HIKkb'><fieldset id='HIKkb'></fieldset></dl></div>

                  <tfoot id='HIKkb'></tfoot>
                    <tbody id='HIKkb'></tbody>
                1. <small id='HIKkb'></small><noframes id='HIKkb'>

                  本文介绍了如何在画布中定位 Path2D SVG 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在画布上绘制一个 path2D SVG 形状.问题是 moveTo 函数在使用 SVG 数据时似乎不起作用.

                  I'm drawing a path2D SVG shape on canvas. The problem is that the moveTo function does not seem to work when using SVG data.

                  此代码笔说明了该问题.https://codepen.io/grasmachien/pen/rNaJeBN

                  The problem is illustrated in this codepen. https://codepen.io/grasmachien/pen/rNaJeBN

                  const canvas = document.getElementById('canvas');
                  const ctx = canvas.getContext('2d');
                  
                  let p = new Path2D('M10 10 h 80 v 80 h -80 Z');
                  p.moveTo(100,100)
                  ctx.fill(p);
                  

                  有没有办法在不移动画布的情况下移动路径?

                  Is there a way to move the path without moving the canvas?

                  推荐答案

                  使用变换移动路径

                  使用 CanvasRenderingContext2D.translate

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

                  或使用 CanvasRenderingContext2D.setTransform

                  let p = new Path2D('M10 10 h 80 v 80 h -80 Z');
                  ctx.setTransform(1, 0, 0, 1, 100, 100);  // Also resets the transform before applying
                  ctx.fill(p);
                  

                  或使用 CanvasRenderingContext2D.transform

                  let p = new Path2D('M10 10 h 80 v 80 h -80 Z');
                  ctx.transform(1, 0, 0, 1, 100, 100);  
                  ctx.fill(p);
                  

                  这篇关于如何在画布中定位 Path2D SVG 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How does object-fit work with canvas element?(对象适合如何与画布元素一起使用?)
                  How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)

                      <bdo id='YWUX3'></bdo><ul id='YWUX3'></ul>

                        <small id='YWUX3'></small><noframes id='YWUX3'>

                          <tbody id='YWUX3'></tbody>

                          <i id='YWUX3'><tr id='YWUX3'><dt id='YWUX3'><q id='YWUX3'><span id='YWUX3'><b id='YWUX3'><form id='YWUX3'><ins id='YWUX3'></ins><ul id='YWUX3'></ul><sub id='YWUX3'></sub></form><legend id='YWUX3'></legend><bdo id='YWUX3'><pre id='YWUX3'><center id='YWUX3'></center></pre></bdo></b><th id='YWUX3'></th></span></q></dt></tr></i><div id='YWUX3'><tfoot id='YWUX3'></tfoot><dl id='YWUX3'><fieldset id='YWUX3'></fieldset></dl></div>

                        1. <legend id='YWUX3'><style id='YWUX3'><dir id='YWUX3'><q id='YWUX3'></q></dir></style></legend>
                        2. <tfoot id='YWUX3'></tfoot>