Can a canvas handle double numbers as points?

Is canvas capable of handling double numbers like 0.5, 10.4 , etc.? Or will it be rounded internally to an integer (if so, how?).

I ask because I think the elements on the canvas are represented as pixels.

And since a pixel always has a size of 1x1 (correct me if I'm wrong), is there an advantage to more accurate drawing if I put double values ​​in the canvas function rather than integer ?

+4
source share
2 answers

Fractional coordinates are possible since the browser can use them to interpolate things at the pixel level. To describe these results in smoothing, while for internal pixels this interpolation can make things a bit fuzzy. In particular, if your object is not formed by separate pixels, but instead something is pretty smooth, for example. circle, then rendering at the subpixel level can give users the impression of a higher resolution than it is actually physically possible, due to the way we perceive the smooth outline.

But since raina77ow stated in a comment on your question , this is due to the conditions for adding work to the browser, which leads to poor performance. Therefore, I would use these recommendations to make a decision:

  • If the drawing subject consists of areas of pixels, all filled with the same color and high contrast between adjacent areas, then I would use integral coordinates, since double coordinates will cause blur, which may look bad.
  • If you do a little not too often, and geometric accuracy is desirable, use double coordinates.
  • If you need to worry about performance, use integer coordinates.

As your question is also tagged : Take a look at RenderingHints . The motion control setting will control whether the coordinates will be rounded in some cases or not, while the smoothing and interpolation settings will affect how fractional positions are displayed, the first for vector paths and the second for bitmap images.

+1
source

No, I don’t think the canvas can use double dots. Although the job is to output the double to int. Thus, the number is treated as an int and works as usual. Casting is as follows:
db.drawImage(image, (int) x, (int) y;
I use this in my games and it works great.

0
source

All Articles