ImageRaster reading 32bit images on device that only supports 16bit color debth


I’m almost finished with my first jmonkey game project.

So far I was able to resolve all my issues thanks to the great documentation of this engine!

While testing my game on different android devices I ran into a little problem I couldn’t resolve so far:

I handle collision detection of my level using *.png images. Reading the level height on the red channel, special zones on the green channel and static collision objects on the blue channel.

For this to work properly I need to be able to read the exact color of the pixel. Currently I read the pixel values using ImageRaster.

This works perfectly on most devices I tested, except my old Samsung Galaxy S GT-9000. The game is rendered in 16 Bit, which is fine, but unfortunately ImageRaster reads my “collision images” in the 16 bit format also. Which leads to a very steppy height detection.

Is there a way to read the pixel values of an image directly into an array regardless of the supported color debth?
I already tried javax imageIO which works fine on pc but doesn’t work on android at all.

To better understand what I’m talking about:

[java]Image image = assetManager.loadTexture(<path/to/image.png>).getImage();
ImageRaster imageRaster = ImageRaster.create(image);

ColorRGBA clr = imageRaster.getPixel(x, y);
float height = clr.r;
float zone = clr.g;
float collision = clr.b;

Thank you in advance!

jME3 uses Android API to decode the image, and images are generally used as textures, not for data. The device is free to make a compromise on the format to improve performance. Older Android devices had a framebuffer that was 16-bit, in that case, it is pointless to decode images as 24-bit since you will never see those extra bits.

One thing you can try is to add an alpha channel to the image, which will then make it impossible to decode as RGB565 (16-bit) and force it to be decoded as ARGB8 - this is kind of a workaround / hack.

Thank you for the quick reply!

My images did already have an alpha channel… but it was not used. To make sure the channel didn’t get lost due to compression I added some transparency to my images. Unfortunately the images were still decoded as RGB565. The alpha value was added to the other channels (alpha value of 0 equals white etc…).

Are there other ways to decode the image?

I was hoping to get around converting my images to bitmaps and decoding them as binary files…

So the device kills the alpha channels for all loaded images? I am sorry, it seems you have a broken device then…

If I were you, I would play with the BitmapFactory class in Android and see what parameters need to be passed in order for the image to be loaded properly on that device.

No it doesn’t :slight_smile: I got your trick to work after all and it works perfectly!
Thank you!

It doesn’t work if every pixel in your alpha channel is set to 1.0. Then the channel gets lost due to compression. The first time I added some additional transparency the editor messed up my other color channels and the image got encoded wrong. Which of course means it will be decoded wrong also :wink: (Sorry about that!)

Now I just set the alpha value of one pixel per image to 0 and it works perfectly.

Thank you again for helping me resolve this issue so quickly!