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

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

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

        HTML5 Canvas - 混合多个 translate() 和 scale() 调用

        HTML5 Canvas - Mixing multiple translate() and scale() calls(HTML5 Canvas - 混合多个 translate() 和 scale() 调用)
        <tfoot id='CqQj4'></tfoot>

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

                <tbody id='CqQj4'></tbody>

              1. <i id='CqQj4'><tr id='CqQj4'><dt id='CqQj4'><q id='CqQj4'><span id='CqQj4'><b id='CqQj4'><form id='CqQj4'><ins id='CqQj4'></ins><ul id='CqQj4'></ul><sub id='CqQj4'></sub></form><legend id='CqQj4'></legend><bdo id='CqQj4'><pre id='CqQj4'><center id='CqQj4'></center></pre></bdo></b><th id='CqQj4'></th></span></q></dt></tr></i><div id='CqQj4'><tfoot id='CqQj4'></tfoot><dl id='CqQj4'><fieldset id='CqQj4'></fieldset></dl></div>
              2. <legend id='CqQj4'><style id='CqQj4'><dir id='CqQj4'><q id='CqQj4'></q></dir></style></legend>
                  <bdo id='CqQj4'></bdo><ul id='CqQj4'></ul>
                  本文介绍了HTML5 Canvas - 混合多个 translate() 和 scale() 调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我只是想知道 Canvas 转换是如何工作的.假设我有一个画布,里面有一个圆圈,我想缩放圆圈,所以它的中心点不会移动.所以我想到了做以下事情:

                  I just wonder how do the Canvas transformations work. Lets say i have a canvas with a circle drawn somewhere inside of it, and i want to scale the circle, so its center point will not move. So i thought about doing the following:

                  translate(-circle.x, -circle.y);
                  scale(factor,factor);
                  translate(circle.x,circle.y);
                  
                  // Now, Draw the circle by calling arc() and fill()
                  

                  这是正确的方法吗?我只是不明白画布是否旨在记住我称之为转换的顺序.

                  Is it the right way to do it? I just don't understand whether the canvas was designed to remember the order that i call the transformations.

                  谢谢.

                  推荐答案

                  是的,你是对的.

                  画布会累积所有变换并将它们应用到任何未来的绘图中.

                  因此,如果您缩放 2X,您的圆圈将以 2X 绘制......并且(!)之后的每次绘制都将是 2X.

                  So if you scale 2X, your circle will be drawn at 2X…and(!) every draw after that will be 2X.

                  这就是保存上下文有用的地方.

                  That’s where saving the context is useful.

                  如果你想将你的圆圈缩放 2 倍,但随后的每个绘图都在正常的 1 倍,你可以使用这种模式.

                  If you want to scale your circle by 2X but then have every subsequent drawing be at normal 1X you can use this pattern.

                  // save the current 1X context
                  Context.save();
                  
                  // move (translate) to where you want your circle’s center to be
                  Context.translate(50,50)
                  
                  // scale the context
                  Context.scale(2,2);
                  
                  // draw your circle
                  // note: since we’re already translated to your circles center, we draw at [0,0].
                  Context.arc(0,0,25,0,Math.PI*2,false);
                  
                  // restore the context to it’s beginning state:  1X and not-translated
                  Context.restore();
                  

                  在 Context.restore 之后,您的平移和缩放将不适用于进一步的绘图.

                  After Context.restore, your translate and scale will not apply to further drawings.

                  这篇关于HTML5 Canvas - 混合多个 translate() 和 scale() 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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(我想沿特定路径对对象进行动画处理)
                • <tfoot id='luHFd'></tfoot>

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

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

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

                            <tbody id='luHFd'></tbody>
                          <legend id='luHFd'><style id='luHFd'><dir id='luHFd'><q id='luHFd'></q></dir></style></legend>