Search code examples
androidimagebitmapfloating-pointdrawbitmap

Android - float parameters in drawBitmap


I used this function in my Android program:

public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)

However, I want to draw my bitmap not in the position 0 x 0, but in the position 10 x 10 (in PIXELS). The drawBitmap function, however, only accepts float numbers...

How can I achieve this??

Thank you in advance!


Solution

  • Have you tried drawBitmap(bitmap, 10.f, 10.f, ... )? Considering the transformation matrix of the canvas is set to the identity matrix, that is.

    The reason those parameters are float is probably that the Canvas does not operate in an integer space (pixels), but in a user specified space defined by a transformation matrix. If you where to set a custom transformation matrix to scale by 2 then using 0.5, 0.5 would end up mapping to pixel 1, 1. This means you could also set a custom transformation to translate by 10, 10 and then just simply draw the bitmap without specifying a destination.