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.

Export Canvas as PNG does decrease the quality of the image

See original GitHub issue

It seems like the renderer.extract.canvas function is decreasing the quality of the canvas. Is there a possability to change that behaviour by another function or some parameter?

The prepared example that demonstrates that issue is located under Example (Stackblitz). If you check that out you will find a canvas with some example object + a button that exports the canvas as a PNG via renderer.extract.canvas. You will notice that the quality of the exported PNG has some problems if you zoom to the circle: image

The interesting thing here is that if I export the canvas via right click “Save image as” the quality is much better (there are less pixalated borders): image

The problem is that this solution is not acceptable as in my application there is also such a button that will trigger the export. Also it seems like the problem is getting bigger with bigger canvas sizes. If I export the canvas as a PNG inside the application I am getting the following pixelated image: image

In the actual canvas that looks like that: image

Expected Behavior

Actually I would expect the exported PNG to look like the canvas, so it should not decrease the quality of the images.

Current Behavior

There are pixelated parts which are not pixelated on the canvas.

Steps to Reproduce

Open stackblitz, press on the button “Save PNG” to export the pixelated image. Then right click on the canvas, select “Save image as” and compare the 2 images.

Example (Stackblitz)

Environment

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
styriandevcommented, Oct 24, 2022

Thanks for pointing that workaround. Unfortunally this does not work as it is only exporting one specific part of the canvas (I guess the part that is visible). As we have a Zoom feature as well as a scroll to specific parts of the canvas this could lead to different screenshots for the same canvas which is not the solution that we need. However, if I scroll out and create a screenshot of the whole canvas the quality of the image is the following:

image

So as you see not really good. I have used the following command to get the blob (after the app.renderer was called): this.app.renderer.plugins.extract.canvas().toBlob(blob =>{…}, ‘image/png’, 0);

I have also tried to change the last parameter to 1 but this does not help.

0reactions
domis86commented, Oct 25, 2022

Maybe solution like this? :

  1. Zoom to desired level.
  2. “Move” canvas to see top left corner of whole scene.
  3. Extract canvas image and save it in some “buffer”.
  4. “Move” canvas to the right.
  5. Repeat points 3 and 4 until you reach right side of scene.
  6. Move canvas to see next chunk (row) of scene on the left.
  7. Repeat points 3,4,5,6 until you scan whole scene.
  8. Somehow join extracted chunks into one image 😃

In other words: extract chunks of scene and glue those images together into one image.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does Canva Reduce Image Quality? - Adventures with Art
Canva does not reduce image quality, but it's easy to pick the wrong download setting and end up with a blurry design. It's...
Read more >
What is the best practice to export canvas with high quality ...
Basically what I do is the following: - draw the canvas (uploading images, put text, etc…); - resize the canvas multiplying by scale...
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 >
Why Are My Canva Design Downloads Blurry?
PNG is what you call a lossless image quality compression. You can save and share these images without losing quality in your images....
Read more >
How to save HTML Canvas as an Image - Fjolt
Saving images from canvas as other formats # · type , which is a filetype, in the format image/png . · encoderOptions ,...
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