Note that there are some explanatory texts on larger screens.

plurals
  1. POGet buffered image from byte array of raw data
    primarykey
    data
    text
    <p>I am using JNA. and i am getting byte array of raw data from my c++ method. Now i am stuck how to get buffered image in java using this raw data byte array. I had tried few things to get it as tiff image but i dint get success. this are the code i tried so far. here my byte array contains data for 16 bit gray scale image. i get this data from x-sensor device. and now i need to get image from this byte array. </p> <p><strong>FIRST TRY</strong></p> <pre><code>byte[] byteArray = myVar1.getByteArray(0, 3318000);//array of raw data ImageInputStream stream1=ImageIO.createImageInputStream(newByteArrayInputStream(byteArray)); ByteArraySeekableStream stream=new ByteArraySeekableStream(byteArray,0,3318000); BufferedImage bi = ImageIO.read(stream); </code></pre> <p><strong>SECOND TRY</strong></p> <pre><code> SeekableStream stream = new ByteArraySeekableStream(byteArray); String[] names = ImageCodec.getDecoderNames(stream); ImageDecoder dec = ImageCodec.createImageDecoder(names[0], stream, null); //at this line get the error ArrayIndexOutOfBoundsException: 0 RenderedImage im = dec.decodeAsRenderedImage(); </code></pre> <p>I think i am missing here. As my array is containing raw data ,it does not containthen header for tiff image. m i right? if yes then how to provide this header in byte array. and eventually how to get image from this byte array?</p> <p>to test that i am getting proper byte array from my native method i stored this byte array as .raw file and after opening this raw file in ImageJ software it sows me correct image so my raw data is correct. The only thing i need is that how to convert my raw byte array in image byte array? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload