3

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.

orde
  • 5,233
  • 6
  • 31
  • 33
mschoenebeck
  • 377
  • 3
  • 12
  • Do you need `1 byte pre-pixel` to `4 byte per-pixel` data translation ? you could pad three bytes of 0's to right of each byte. – S.D. May 22 '13 at 17:22
  • yes, but then I would have to modify/increase the array-size what is very time- and memory-expensive. I'm looking for another way without having to modify the array. – mschoenebeck May 22 '13 at 17:46
  • 1
    Example of making an Android compliant bitmap from a grayscale image [here](http://stackoverflow.com/questions/5626795/how-to-get-a-bitmap-from-a-raw-image/5636912#5636912). – Seva Alekseyev May 22 '13 at 18:29
  • @mschoenebeck The `setPixels()` if `Bitmap` is implemented natively, so there's no chance of overriding it to use `1bpp` array. Only solution is to create another array as pointed out by others. – S.D. May 23 '13 at 02:24

1 Answers1

0

have a look here: Render a byte[] as Bitmap in Android and adapt it to your problem.

And just in case, ARGB_8888 means 1byte per channel (alpha, red, green, blue) for 1 pixel and happily equals 32 bit.

Community
  • 1
  • 1
sschrass
  • 7,014
  • 6
  • 43
  • 62