Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Bitmap.createBitmap() returning a bitmap with -1 for height and width

Why would

Bitmap bmp;
bmp = Bitmap.createBitmap( 100, 100, Config.RGB_565 );

Ever return a bitmap with a height and width of -1? I don't see anything in the documentation about this. Only see this in the documentation

Throws

IllegalArgumentException if the width or height are <= 0

But while debugging in eclipse I see the width and height are -1 after creation. Everything seems to display correctly.

[Update]

If I add a Log and get the width and height

Log.i(logTag, "bmp - (width,height) (" + bmp.getWidth() + "," + bmp.getHeight() + ")");

Then look at the properties of the bitmap, the correct width and height are shown (I'm assuming any call to read the width and height after creation would then update the properties in eclipse and it will show correctly).

I guess this is just a debugger issue? I'm debugging on my old Droid.

like image 435
Jerinaw Avatar asked Jul 24 '11 17:07

Jerinaw


1 Answers

Are you in a situation where this is an issue? Or merely curious why they are -1?

Either way it is not a debugger issue, the properties are actually -1. This is just speculation but until the Bitmap is used/drawn the width and height can be -1 because it doesn't matter and is likely an optimization in the implementation.

like image 130
smith324 Avatar answered Oct 22 '22 10:10

smith324