Ajay
Ajay

Reputation: 437

Creating bitmaps not working

For some reason my bitmap creation is not working. Have I found a bug? When I try to make a new bitmap using a Matrix, it says my width and height must be over 0 which makes no sense.

Bitmap tempbmp = Bitmap.createBitmap(image1, 0, 0, newwidth, newheight, matrix, true);

I know it might seem like I haven't done any research, I have and it makes no sense. I have tried manythings including changing newwidth and newheight to constants and it still does not work. Here is the stack track trace if that helps

11-03 18:32:00.700: E/AndroidRuntime(9113): java.lang.IllegalArgumentException: width and height must be > 0
11-03 18:32:00.700: E/AndroidRuntime(9113):     at android.graphics.Bitmap.createBitmap(Bitmap.java:603)
11-03 18:32:00.700: E/AndroidRuntime(9113):     at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
11-03 18:32:00.700: E/AndroidRuntime(9113):     at com.ajayinkingston.antiverse.Level.tick(Level.java:291)
11-03 18:32:00.700: E/AndroidRuntime(9113):     at com.ajayinkingston.antiverse.Logic.tick(Logic.java:65)
11-03 18:32:00.700: E/AndroidRuntime(9113):     at com.ajayinkingston.antiverse.GameView.run(GameView.java:142)
11-03 18:32:00.700: E/AndroidRuntime(9113):     at java.lang.Thread.run(Thread.java:856)

I am trying to make a spinning portal. I wanted to have a matrix translate, rotate and scale but I did not get that working. I decided to take out the translation and just make an image and later draw the image. The matrix is created here:

matrix.reset();             
matrix.setScale((newwidth)/image1.getWidth(), (newheight)/image1.getHeight());
matrix.postRotate(rotation, image1.getWidth()/2 + x, image1.getHeight()/2 + y);

The values of newwidth and newheight do not matter as this error happens with constants.

Upvotes: 1

Views: 126

Answers (2)

Ajay
Ajay

Reputation: 437

I could not find out why. So, I decided to do it another way. I removed the matrix.setScale() and just used bitmap.createScaledBitmap() later.

Upvotes: 0

vvg
vvg

Reputation: 6385

Checked code of Bitmap.java Those exception happened if image1 width orheight is 0.

upd. or matrix is empty.

https://github.com/android/platform_frameworks_base/blob/master/graphics/java/android/graphics/Bitmap.java#L680

Upvotes: 1

Related Questions