简体   繁体   English

执行canvas.toDataUrl()时为空白图像

[英]Blank image when executing canvas.toDataUrl()

  1. Go to this website . 这个网站

  2. Open up the console and write: 打开控制台并输入:

` `

var canvas = $("#mandelbox-canvas")[0];
var imgData = canvas.toDataURL("image/png").split(',')[1];
console.log(imgData);
  1. Copy the data URL and paste into this site . 复制数据URL并粘贴到此站点中

在此处输入图片说明

Why is the image blank? 为什么图像空白? How can I fix this? 我怎样才能解决这个问题?

Things I have already tried: 我已经尝试过的事情:

I have tried the solution to this question . 我已经试过解决这个问题 IE This code: IE这段代码:

var canvas = $("#mandelbox-canvas")[0];
canvas.getContext('webgl',{preserveDrawingBuffer:true});
var imgData = canvas.toDataURL("image/png").split(',')[1];
console.log(imgData)

however the image is still blank. 但是图像仍然空白。 The image does not contain the image displayed on the canvas. 该图像不包含在画布上显示的图像。

So after much trawling through StackOverflow I found the function drawScene() which (somehow?) force toDataURL() to return the image data as required: 因此,在对StackOverflow进行了很多拖曳之后,我发现了函数drawScene() (以某种方式)强制toDataURL()根据需要返回图像数据:

var canvas = $("#mandelbox-canvas")[0];
drawScene()
var imgData = canvas.toDataURL("image/png").split(',')[1];
console.log(imgData)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM