Search code examples
javascripthtmlhtml5-canvas

Canvas resolution and export resolution


I have canvas which is width="600px" and height="500px".

then I show the image(1200px and 1000px) on this canvas

ctx.drawImage(img,600,500);

finally export with this script.

var a = document.createElement('a');
a.href = mycanvas.current.toDataURL('image/jpeg', 0.85);

In this case jpg's final resolution is 600px x 500px.

However I want to keep final resolution 1200 x 1000 jpg.

What is the best practice for this purpose.


Solution

  • I use clientWidth and width

    use clientWidth = 600 and width = 1200

    It can be done.