Skip to content Skip to sidebar Skip to footer

Create A Bitmap Using Double Values Instead Of Int Android

In my code I need create a Bitmap using double values. It´s important use the correct value. I´m using: Bitmap bmp = Bitmap.createBitmap(int, int, Bitmap.Config.ARGB_8888); ...

Solution 1:

Perhaps I misunderstand the question, but bitmaps are rasters of whole pixels. You can't have fractions of pixels, so you can only have integer numbers of rows and columns in the parameters for createBitmap.

Having said that, you can rescale how the bitmap is drawn using float scale factors applied via Matrix drawBitmap methods, e.g.

Canvas.drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint)

Matrix matrix = new android.graphics.Matrix();
matrix.postScale(3.14f, 3.14f);
canvas.drawBitmap(bitmap, matrix, paint);

However, when it comes to rendering this on screen, it will again draw only whole pixels, so you still don't get fractional pixels displayed.


Solution 2:

Try this, convert double to int:

double myDouble = 10.4;
int myInt = (int) (myDouble);

Using (int) casts the double into an int


Post a Comment for "Create A Bitmap Using Double Values Instead Of Int Android"