[英]Blank image when executing canvas.toDataUrl()
Go to this website . 去这个网站 。
Open up the console and write: 打开控制台并输入:
` `
var canvas = $("#mandelbox-canvas")[0];
var imgData = canvas.toDataURL("image/png").split(',')[1];
console.log(imgData);
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.