title: Trying to read raw image data into Java through JNI
body: <p>I'm using JNI to obtain raw image data in the following format: </p>
  
  <p>The image data is returned in the format of a DATA32 (32 bits) per pixel in a linear array ordered from the top left of the image to the bottom right going from left to right each line. Each pixel has the upper 8 bits as the alpha channel and the lower 8 bits are the blue channel - so a pixel's bits are ARGB (from most to least significant, 8 bits per channel). You must put the data back at some point.</p>
  
  <p>The DATA32 format is essentially an unsigned int in C. </p>
  
  <p>So I obtain an int[] array and then try to create a Buffered Image out of it by</p>
  
  <pre><code>        int w = 1920;
          int h = 1200;
  
          BufferedImage b = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 
  
  
          int[] f = (new Capture()).capture();
          for(int i = 0; i &lt; f.length; i++){;
                  b.setRGB(x, y, f[i]);
          }
  </code></pre>
  
  <p>f is the array with the pixel data.</p>
  
  <p>According to the Java documentation this should work since BufferedImage.TYPE_INT_ARGB is:</p>
  
  <p>Represents an image with 8-bit RGBA color components packed into integer pixels. The image has a DirectColorModel with alpha. The color data in this image is considered not to be premultiplied with alpha. When this type is used as the imageType argument to a BufferedImage  constructor, the created image is consistent with images created in the JDK1.1 and earlier releases.</p>
  
  <p>Unless by 8-bit RGBA, them mean that all components added together are encoded in 8bits? But this is impossible.</p>
  
  <p>This code does work, but the image that is produced is not at all like the image that it should produce. There are tonnes of artifacts. Can anyone see something obviously wrong in here? </p>
  
  <p>Note I obtain my pixel data with</p>
  
  <pre><code>imlib_context_set_image(im);
  data = imlib_image_get_data();
  </code></pre>
  
  <p>in my C code, using the library imlib2 with api <a href="http://docs.enlightenment.org/api/imlib2/html/imlib2_8c.html#17817446139a645cc017e9f79124e5a2" rel="nofollow noreferrer">http://docs.enlightenment.org/api/imlib2/html/imlib2_8c.html#17817446139a645cc017e9f79124e5a2</a></p>