HTML5 canvas stroke() thick and fuzzy

Nona Urbiz picture Nona Urbiz · Oct 21, 2010 · Viewed 27.8k times · Source

I'm trying to allow the user to draw a rectangle on the canvas (like a selection box). I'm getting some ridiculous results, but then I noticed that even just trying the code from my reference here, I get huge fuzzy lines and don't know why.

it's hosted at dylanstestserver.com/drawcss. the javascript is inline so you can check it out. I am using jQuery to simplify getting the mouse coordinates.

Answer

DougLeary picture DougLeary · Oct 12, 2012

The blurry problem will happen if you use css to set the canvas height and width instead of setting height and width in the canvas element.

<style>
  canvas { height: 800px; width: 1200px; }      WRONG WAY -- BLURRY LINES
</style>

<canvas height="800" width="1200"></canvas>     RIGHT WAY -- SHARP LINES