question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When I convert stage canvas to png, sometimes the image is full with black

See original GitHub issue

I use toDataUrl to convert stage canvas to png, but sometimes the image is all black and with nothing else. Miraculously, there are times when the image displays the contents of the canvas normally. Does anyone know why?

Here is my code:

const canvas = document.querySelector('.stage_stage_1fD7k');
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);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

github_iconTop Results From Across the Web

When I convert canvas to png, sometimes the image is full with ...
One possibility is that the background of the canvas is transparent. Transparent PNGs in some editors (like MS Paint) appear with a black ......
Read more >
HTML5 Canvas Export to High Quality Image Tutorial - Konva
How to export a high quality image from a stage?If you need to export a stage as an image or as base64 then...
Read more >
How to Resolve Color Banding in Your Images
Open the actual file in an editor like Photoshop or Lightroom and zoom in to view the banding at 100% scale. Verify whether...
Read more >
Saving For The Web — Krita Manual 5.0.0 documentation
Use this for images with few colors or which are black and white, like comics and pixel-art. Select Save as indexed PNG, if...
Read more >
ImageMagick Examples -- Multi-Image Layers
Flatten - onto a Background Image; Mosaics - Canvas Expanding ... Layering Thumbnails; Calculated Positioning of Images; Two Stage Positioning of Images ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found