Canvas text rendering (blurry)

后端 未结 4 2026
难免孤独
难免孤独 2020-12-03 08:14

I know this question has been asked many times, but I tried pretty much everything I could find on the net and still can\'t get the text to render properly in canvas no matt

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 09:10

    There is, however, a simpler solution.

        context.scale(0.3, 0.3)
        context.fillText("Hello there", canvas.width / 2 * 1 / 0.3, canvas.height * 2.8 / 4 * 1 / 0.3, canvas.width * 0.9 * 1 / 0.3);
        context.font = canvas.width / 15 + "px Arial";
        context.fillText("Want to talk? Mail me at mher@movsisyan.info", canvas.width / 2 * 1 / 0.3, canvas.height * 3.6 / 4 * 1 / 0.3, canvas.width * 0.9 * 1 / 0.3);
        context.fillText("Want to see my code? Find me on GitHub as MovsisyanM", canvas.width / 2 * 1 / 0.3, canvas.height * 3.8 / 4 * 1 / 0.3, canvas.width * 0.9 * 1 / 0.3);
        context.scale(1, 1)
    

    Here I scale down the canvas context, which lets me use higher font px thus having better quality text.

    I actually found out this technique because photoshop or some similar image editing program had the same problem. I hope this helps!

提交回复
热议问题