• <legend id='KbJBx'><style id='KbJBx'><dir id='KbJBx'><q id='KbJBx'></q></dir></style></legend>

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

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

        • <bdo id='KbJBx'></bdo><ul id='KbJBx'></ul>

        是否可以创建没有 DOM 元素的 HTML 画布?

        Is it possible to create an HTML canvas without a DOM element?(是否可以创建没有 DOM 元素的 HTML 画布?)
      1. <small id='gYBHJ'></small><noframes id='gYBHJ'>

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

                2. 本文介绍了是否可以创建没有 DOM 元素的 HTML 画布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想要一个 HTML 画布上下文,我可以在屏幕外绘制和读取(在此示例中,编写文本和读取创建的形状,但这是一个普遍的问题).我可能还想使用画布作为屏幕外帧缓冲区.

                  I'd like to have an HTML canvas context that I can paint to and read off-screen (in this example, writing text and reading the shape that is created, but it's a general question). I may also want to use a canvas as an off-screen frame-buffer.

                  我想我可以创建一个隐藏的 DOM 元素,但我宁愿从 JavaScript 创建它(我可能想在运行时创建和销毁一些画布).

                  I suppose I could create a hidden DOM element but I'd rather create it from JavaScript (I may want to create and destroy a number of canvas at runtime).

                  可能吗?

                  推荐答案

                  您可以使用 document.createElement 创建一个新的 canvas 元素:

                  You can create a new canvas element with document.createElement:

                  var canvas = document.createElement('canvas');
                  

                  然后从中获取上下文.只需确保设置了 widthheight.您不必将画布添加到树中即可使其工作:

                  and then get the context from it. Just make sure you set the width and height. You don't have to add the canvas to the tree in order to make it work:

                  演示

                  但您肯定必须创建该节点.不过,您可以为此创建一个函数:

                  But you definitely have to create that node. You could create a function for that though:

                  function createContext(width, height) {
                      var canvas = document.createElement('canvas');
                      canvas.width = width;
                      canvas.height = height;
                      return canvas.getContext("2d");
                  }
                  

                  但这就是我的能力结束的地方...我不知道您是否可以以某种方式将上下文转移到另一个上下文或画布...

                  But that is where my competency ends... whether you can somehow transfer a context to another context or canvas, I don't know...

                  这篇关于是否可以创建没有 DOM 元素的 HTML 画布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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(我想沿特定路径对对象进行动画处理)

                    <tbody id='nlqSE'></tbody>

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

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