Damir
Damir

Reputation: 399

Bitmap.createBitmap() on Android 2.2 issue

I have tested my game on HTC Desire with Android 2.2. Game is 2D with custom defined sprites with multiple bitmap images (frames). Frames are generated from one larger image using method Bitmap.createBitmap():

bitmapFrames[currentFrame][0] = Bitmap.createBitmap(image, startX, startY, width, height, matrix, true);

It works ok on Android 1.5 and 1.6 devices. Also it works ok on all emulators (1.5, 1.6, 2.1 and 2.2) but on real HTC Desire device all sprite frames are drawn. It looks like above mentioned method ignore parameters startX, startY, width, height when creating bitmap frame.
Any clue about this issue?

Upvotes: 2

Views: 6673

Answers (1)

Damir
Damir

Reputation: 399

OK, I found solution for this problem. Let me explain where issue arise: I noticed that my tiles do not have same problem as sprites even they are created on same way. This is because for tile images I didn't use transparency. Conclusion is:
If you are using solid Bitmap image
bmpImage.getConfig() == Config.RGB_565
then above mentioned method works fine. But, if you are using transparency
bmpImage.getConfig() == Config.ARGB_8888
then method
Bitmap.createBitmap(image, startX, startY, width, height, matrix, true);
always return whole bitmap image instead just one part. This issue only exist on Android 2.2 real device.

Solution:
I had manualy to copy Color values from source image and create frames using parts of int[] color values using below methods:

  • Bitmap.getPixels()

  • System.arraycopy()

  • Bitmap.createBitmap(int[] colors, int width, int height, Bitmap.Config config)

Upvotes: 6

Related Questions