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.

Canvas rendering is blurry on retina displays

See original GitHub issue

Thanks for the great library! One thing I’m noticing though is that the screenshots are blurry when using a retina display. For example, here’s what the screenshot of https://github.com/niklasvh/html2canvas looks like on a retina display (as taken from the test page). screen shot 2014-05-24 at 1 29 51 pm

I think maybe there needs to be a check for the ratio between the window.devicePixelRatio and the context.backingStorePixelRatio somewhere in the rendering of the canvas…?

p.s. Here are some useful links I came across while trying to get to the root of the issue.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:38 (2 by maintainers)

github_iconTop GitHub Comments

52reactions
MisterLambcommented, Apr 10, 2016

Apparently you can use an existing canvas for rendering (which you can preconfigure to be displayed in retina).

Example:

var w = 1000;
var h = 1000;
var div = document.querySelector('#divtoconvert');
var canvas = document.createElement('canvas');
canvas.width = w*2;
canvas.height = h*2;
canvas.style.width = w + 'px';
canvas.style.height = h + 'px';
var context = canvas.getContext('2d');
context.scale(2,2);
html2canvas(div, { canvas: canvas }).then(function(canvas) {
    // do what you want
});
5reactions
breimcommented, Aug 29, 2015

@zqcloveping Bro, try this configs, not solve 100% but increases quality

html2canvas(document.getElementById(‘flag’), { useCORS: true, allowTaint: true, letterRendering: true, onrendered: function(canvas) { var ctx = canvas.getContext(‘2d’); ctx.webkitImageSmoothingEnabled = false; ctx.mozImageSmoothingEnabled = false; ctx.imageSmoothingEnabled = false; }, });

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ensuring our Canvas Looks Good on Retina/High-DPI Screens
As we know from scaling up raster images like PNGs and JPEGs, doing this will result in our image appearing blurry. This is...
Read more >
How to make the canvas not look like crap on retina - Coderwall
Be careful: without a slight tweak, this approach is making your canvas slightly blurrier for non-retina users, and making them do much more ......
Read more >
SVG rendered into canvas blurred on retina display
First is to turn of bilinear filtering on the canvas. · When rendering SVG to the canvas you should turn off image smoothing...
Read more >
Retina display, blurry rendering - Google Groups
When it comes to drawing images on canvas, we're pretty much relying on engine's ... So a straight 4px vector line is rendered...
Read more >
GeoExamples - Canvas mapping with a retina display
The image below shows the problem when drawing canvas with a retina display: When setting up a canvas element, the numebr of actual...
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