michael
michael

Reputation: 110600

Why draw operation in android canvas are using float instead of int for (x,y)?

Why draw operation in android canvas are using float instead of int for (x,y)? For example: http://developer.android.com/reference/android/graphics/Canvas.html#drawCircle(float, float, float, android.graphics.Paint)

http://developer.android.com/reference/android/graphics/Canvas.html#drawRect(float, float, float, float, android.graphics.Paint)

If I have a lot of objects (say 200) to draw in my application and i have a class for each object, should I use 'int' or 'float' for the x, y attribute (the location of the object when drawn on screen)? i think 'float' use less memory than 'int'.

class MyObject {
   public int x;
   public int y;
}

Thank you.

Upvotes: 7

Views: 1496

Answers (1)

Kris Van Bael
Kris Van Bael

Reputation: 2862

Float because anti-aliasing allows you to paint at sub-pixel level. Also because there can be a transformation matrix active (e.g. A scale).

A float and int take both 32 bit (most likely)

Upvotes: 6

Related Questions