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

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

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

        通过 canvas.toDataURL 将画布保存到图像会导致黑色矩形

        Saving canvas to image via canvas.toDataURL results in black rectangle(通过 canvas.toDataURL 将画布保存到图像会导致黑色矩形)
          <tbody id='6kMIu'></tbody>
      2. <legend id='6kMIu'><style id='6kMIu'><dir id='6kMIu'><q id='6kMIu'></q></dir></style></legend>

        • <small id='6kMIu'></small><noframes id='6kMIu'>

            <bdo id='6kMIu'></bdo><ul id='6kMIu'></ul>

                <tfoot id='6kMIu'></tfoot>
              1. <i id='6kMIu'><tr id='6kMIu'><dt id='6kMIu'><q id='6kMIu'><span id='6kMIu'><b id='6kMIu'><form id='6kMIu'><ins id='6kMIu'></ins><ul id='6kMIu'></ul><sub id='6kMIu'></sub></form><legend id='6kMIu'></legend><bdo id='6kMIu'><pre id='6kMIu'><center id='6kMIu'></center></pre></bdo></b><th id='6kMIu'></th></span></q></dt></tr></i><div id='6kMIu'><tfoot id='6kMIu'></tfoot><dl id='6kMIu'><fieldset id='6kMIu'></fieldset></dl></div>
                  本文介绍了通过 canvas.toDataURL 将画布保存到图像会导致黑色矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Pixi.js 并尝试将动画帧保存到图像中.canvas.toDataUrl 应该可以工作,但我得到的只是一个黑色矩形.查看现场示例这里

                  Im using Pixi.js and trying to save a frame of the animation to an image. canvas.toDataUrl should work, but all i get is a black rectangle. See live example here

                  我用来提取图像数据并设置图像的代码是:

                  the code I use to extract the image data and set the image is:

                              var canvas = $('canvas')[0];
                              var context = canvas.getContext('2d');
                  
                              $('button').click(function() {
                  
                                  var data = renderer.view.toDataURL("image/png", 1);
                                  //tried var data = canvas.toDataURL();
                                  $('img').attr('src', data);
                              })
                  

                  推荐答案

                  [注意]

                  虽然这个答案是公认的答案,但请阅读下面@gman 的那个,它确实包含更好的方式.

                  [NOTE]

                  While this answer is the accepted one, please do read the one by @gman just below, it does contain a way better way of doing.

                  您的问题是您使用的是 webGL 上下文,那么您需要将 webGL 上下文的 preserveDrawingBuffer 属性设置为 true 以便能够调用 toDataURL() 方法.

                  Your problem is that you are using webGL context, then you need to set the preserveDrawingBuffer property of the webGL context to true in order to be able to call toDataURL() method.

                  或者,您可以强制 pixi 使用 2D 上下文,方法是使用 CanvasRenderer

                  Or alternatively, you can force pixi to use the 2D context, by using the CanvasRenderer Class

                  这篇关于通过 canvas.toDataURL 将画布保存到图像会导致黑色矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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(我想沿特定路径对对象进行动画处理)
                  How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                    <tfoot id='A3g2L'></tfoot>
                  • <i id='A3g2L'><tr id='A3g2L'><dt id='A3g2L'><q id='A3g2L'><span id='A3g2L'><b id='A3g2L'><form id='A3g2L'><ins id='A3g2L'></ins><ul id='A3g2L'></ul><sub id='A3g2L'></sub></form><legend id='A3g2L'></legend><bdo id='A3g2L'><pre id='A3g2L'><center id='A3g2L'></center></pre></bdo></b><th id='A3g2L'></th></span></q></dt></tr></i><div id='A3g2L'><tfoot id='A3g2L'></tfoot><dl id='A3g2L'><fieldset id='A3g2L'></fieldset></dl></div>

                        <tbody id='A3g2L'></tbody>
                        <bdo id='A3g2L'></bdo><ul id='A3g2L'></ul>

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

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