when I use toDataUrl ()
to convert canvas to png, sometimes I get an all-black picture, but the amazing thing is that sometimes the picture is normal, does anyone know what"s going on?
// "stage" canvas
const canvas = document.querySelector(".stage");
const image = canvas.toDataUrl("image/png");
const link = document.createElement("a");
link.href = image;
link.download = "balabala.png";
const event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
link.dispatchEvent(event);