title: Trying to extract the bytes from a PNG image
body: <p>I'm trying to extract the bytes from a PNG and am getting some weird looking results.</p>
  
  <p>Here is my extract byte method:</p>
  
  <pre><code>public static byte[] extractBytes (String ImageName) throws IOException {
       // open image
       File imgPath = new File(ImageName);
       BufferedImage bufferedImage = ImageIO.read(imgPath);
  
       // get DataBufferBytes from Raster
       WritableRaster raster = bufferedImage.getRaster();
       DataBufferByte data   = (DataBufferByte) raster.getDataBuffer();
  
       return ( data.getData() );
  }
  </code></pre>
  
  <p>And here is where I call the function and loop through the resulting byte[]:</p>
  
  <pre><code>byte[] bytes = extractBytes("colorstrip.png");
  
  for (int x : bytes) {
      System.out.println(x);
  }
  </code></pre>
  
  <p>I've been testing this code on a 4x1 image simply containing a red pixel, a blue pixel, a green pixel, and a purple pixel in that order. Here is the output:</p>
  
  <pre><code>-1
  0
  0
  -1
  -1
  0
  -1
  0
  -1
  -1
  0
  0
  -1
  -1
  0
  -1
  </code></pre>
  
  <p>This output does not look correct to me. I believe the output should look something like this (I've left the alpha channels blank):</p>
  
  <pre><code>255
  0
  0
  
  0
  255
  0
  
  0
  0
  255
  
  255
  0
  255
  </code></pre>
  
  <p>Any idea what the problem is?</p>