Android - Read PNG image without alpha and decode as ARGB_8888

Posted by loki666 on Stack Overflow See other posts from Stack Overflow or by loki666
Published on 2010-05-21T12:19:46Z Indexed on 2010/05/21 13:40 UTC
Read the original article Hit count: 292

Filed under:
|
|
|
|

I try to read an image from sdcard (in emulator) and then create a Bitmap image with the

BitmapFactory.decodeByteArray

method. I set the options:

options.inPrefferedConfig = Bitmap.Config.ARGB_8888
options.inDither = false

Then I extract the pixels into a ByteBuffer.

ByteBuffer buffer = ByteBuffer.allocateDirect(width*height*4)
bitmap.copyPixelsToBuffer(buffer)

I use this ByteBuffer then in the JNI to convert it into RGB format and want to calculate on it.

But always I get false data - I test without modifying the ByteBuffer. Only thing I do is to put it into the native method into JNI. Then cast it into a unsigned char* and convert it back into a ByteBuffer before returning it back to Java.

unsigned char* buffer = (unsinged char*)(env->GetDirectBufferAddress(byteBuffer))
jobject returnByteBuffer = env->NewDirectByteBuffer(buffer, length)

Before displaying the image I get data back with

bitmap.copyPixelsFromBuffer( buffer )

But then it has wrong data in it.

My Question is if this is because the image is internally converted into RGB 565 or what is wrong here?

.....

Have an answer for it:

->>> yes, it is converted internally to RGB565.

Does anybody know how to create such an bitmap image from PNG with ARGB8888 pixel format?

If anybody has an idea, it would be great!

© Stack Overflow or respective owner

Related posts about android

Related posts about bitmap