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.

Colors are different depending on physical screen monitor

See original GitHub issue

Bug reports:

The colors are different depending on which monitor I generate and render the canvas.

If I generate the canvas on monitor 2, the PNG is darker. If I generate the canvas on monitor 1, the PNG looks correct.

I tried adding a background color of white to the wrapper div and canvas options but both did not work.

Code (React & Typescript project):

/*

- converts a <div> into a canvas, then sets the dataUrl to the download link: 
<a href={dataUrl} download={fileName} />

- function is called on componentDidUpdate, when data within the wrapper div is updated

*/

async setUpDataUrl(): void {
    try {
      const wrapperRef = this.wrapperRef.current; // <div>
      const downloadLinkRef = this.downloadLinkRef.current; // <a />

        const canvas = await html2canvas(wrapperRef);
        const imgData = canvas.toDataURL('image/png');

        downloadLinkRef.href = imgData;
      
    } catch (e) {
      console.log(e);
    }
  }

Steps to reproduce problem:

MONITOR 1 (Macbook Pro):

1: Data is updated within the wrapper div. This then triggers componentDidUpdate and setUpDataUrl(). 2. The wrapper div and download link are rendered. 3. I click on the download link and download the wrapper div as a PNG file. 4. The PNG looks just the same as the wrapper div: Screen Shot 2020-07-29 at 4 59 14 PM

MONITOR 2 (External portable monitor):

I repeat steps 1-3 above, but the colors are darker: Screen Shot 2020-07-29 at 4 59 04 PM

Specifications:

  • html2canvas version tested with:
  • Browser & version: Chrome 84.0.4147.89
  • Operating system: macOS

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

4reactions
kaydenizcommented, Aug 17, 2020

This solution may be useful for your problem, I use html2canvas in my app like this ;

html2canvas(document.querySelector("#divToPrint"), {scale: '2'}).then(canvas => { const imgData = await canvas.toDataURL('image/png'); });

Before I added {scale: '2'} I had same problem. I hope this method solves your problem.

1reaction
LeLunZcommented, May 30, 2022

Works also in 2022! 😂

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Do Colors Look Different on Computer Monitors ...
Colors look different on computer monitors and cell phone screens. This has to do with pixels, resolution, and the human eye.
Read more >
Colors on A Computer Screen
A monitor or TV screen generates three colors of light (red, green, and blue) and the different colors we see are due to...
Read more >
Color Disclaimer - Balloominators
Actual colors may vary. This is due to computer monitors displaying colors differently and everyone can see these colors differently.
Read more >
Why Colors Look Different on Screen vs. In Print
The reason has to do with light vs. ink. Computers use red, green and blue (RGB) light to display colors, while print uses...
Read more >
RGB vs. CMYK – Why the colors on your monitor might not ...
Whenever something on your computer is printed onto paper or any other type of material, the colors are converted from the electronic display...
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