javascript - HTML5 canvas toDataURL sometimes returns "data:," instead of the image -
i have created canvas document.createelement("canvas")
:
var canvas = document.createelement("canvas"); canvas.width = width; // width = 4000 or more canvas.height = height; // height = 5000 or more
then use canvas.todataurl()
base64 string:
var str = canvas.todataurl();
but 'str' returns "data:,"
, no image data in it. 6 chars.
sometimes returns correct string "data:image/png;base64,ivborw0kggoaaaansuheugaaeggaabpscayaaabg/ah3aaagaeleqvr4xuzcqreaaajdm..."
i canvas.width
large ....
you should try create 2d context explicitly , draw in empty shape, like:
var canvas = document.createelement("canvas"); canvas.width = 4000; canvas.height = 5000; var ctx=canvas.getcontext('2d'); ctx.fillrect(0,0,0,0); canvas.todataurl();
edit: seems canvas contains data exported datauri:
var canvas = document.createelement("canvas"); canvas.width = 400000000; canvas.height = 500000000; var ctx=canvas.getcontext('2d'); ctx.fillrect(0,0,0,0); canvas.todataurl(); // outputs : "data:,"
Comments
Post a Comment