Canvas drawings, like lines, are blurry

前端 未结 10 946
野的像风
野的像风 2020-11-27 15:15

I have a

and canvas, which is drawn using:

context.lineWidth = 1;
context.strokeStyle = \"gray\         


        
10条回答
  •  醉梦人生
    2020-11-27 15:51

    I use a retina display and I found a solution that worked for me here.

    Small recap :

    First you need to set the size of your canvas twice as large as you want it, for example :

    canvas = document.getElementById('myCanvas');
    canvas.width = 200;
    canvas.height = 200;
    

    Then using CSS you set it to the desired size :

    canvas.style.width = "100px";
    canvas.style.height = "100px";
    

    And finally you scale the drawing context by 2 :

    canvas.getContext('2d').scale(2,2);
    

提交回复
热议问题