Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EaselJS line fuzziness

I am using EaselJS as an API for HTML5 canvas.

I noticed that the following code:

line.graphics.setStrokeStyle(1).beginStroke("black").moveTo(100,100).lineTo(200,200);
stage.addChild(line);

...produces following line:

enter image description here

I set the thickness to 1 - but the line is still fuzzy. If you zoom in with the snapshot, you can see it actually occupies 3 pixels. I believe I read somewhere canvas draws a point between two pixels, so that both pixels will be colored in fact. And you need to shift where you draw the point by half the pixel width so it falls on the entire pixel.

I need sharp image for my applications, please advise.

like image 567
William Sham Avatar asked Jul 13 '11 00:07

William Sham


1 Answers

EaselJS is just an abstraction for the canvas APIs - which draws all lines on the specified coordinates. The snapToPixel API is specifically for doing automatic rounding, but doesn't take into account the half-pixel issue you are describing.

The best practice approach is to put everything into a Container, and put the container at positive or negative (0.5,0.5) - which will adjust everything, and you can work in a normal coordinate space, rather than offsetting all your calculations.

like image 159
Lanny Avatar answered Nov 01 '22 22:11

Lanny