I've got some raw picture-files (grayscale-sensordata) where each byte is one pixel grayscale-value. So all pixels are 8-bit values. In my native Code, I work on that (raw) bytes (image processing), and, after that, I pass the byte-array to the Java-VM with a DirectByteBuffer (Java-NIO).
In my Java-Code, I would like to draw the image-data in an ImageView. Therefore, I use a Bitmap where I put my Image data into. Here's what I do on the Java side:
// getLeftImageData() is the native function that returns the
// DirectByteBuffer with the imagedata to be drawn. Each Byte
// is one pixel value.
IntBuffer leftImageData = getLeftImageData().asIntBuffer();
int[] arrayL = new int[leftImageData.remaining()];
leftImageData.get(arrayL);
Bitmap.Config conf = Bitmap.Config.ARGB_8888;
Bitmap bmpL = Bitmap.createBitmap(1920/4, 1080/4, conf);
bmpL.setPixels(arrayL, 0, 1920, 0, 0, 1920/4, 1080/4);
ImageView imageL = (ImageView)findViewById(R.id.imageLeft);
imageL.setImageBitmap(bmpL);
And here is my Problem. Everything works fine so far but:
The setPixels()
method expects an int array where each int-value must be one pixel value. Therefore, I look at the DirectByteBuffer as an IntBuffer (asIntBuffer()-method). But this is not really what I want because now 4 pixels (=4 bytes) are put together to one integer-pixel value now. Do you see what I mean? There is no way to set the Pixels of a bitmap with an byte-array. You can only pass an integer-array. So I would have to modify my byte-array (and of course increase it with 4x of the original size) only to have my 8-bit values in a 32-bit integer format.
Do you have any Idea, how I can display the image data in an android ImageView without having to modify the byte-array? Maybe there is a way without using a bitmap or stuff..? I'm pretty new to android btw.