title: Trying to Draw a 24bit image in Java
body: <p>I have an image that where each pixel is 4 byte i.e. red mask is 0xFF0000 green is 0xFF00 and blue 0xFF. I read in the image and pass it to a function as function(byte imgBuff,int w,int h)
  I then have</p>
  
  <pre><code>  void fun(byte imgBuff,int w,int h)
    {
        Graphics g;
        BufferedImage img;
        DataBuffer dBuffer = new DataBufferByte(imgBuff, w * h);
        WritableRaster wr = Raster.createPackedRaster(dBuffer,w,h,24,null);
        DirectColorModel dcm = new DirectColorModel(24,0xFF0000,0xFF00,0xFF);
        img = new BufferedImage(dcm,wr,false,null);
        g = getGraphics();
        g.drawImage(img,x,y,w,h,null);
    }
  </code></pre>
  
  <p>But when I run I get </p>
  
  <blockquote>
    <p>Exception in thread "Thread-23" java.lang.IllegalArgumentException:
    Raster sun.awt.image.SunWritableRaster@1d82ed7 is incompatible with
    ColorModel DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0</p>
  </blockquote>
  
  <p>How do I go from bytebuffer via <code>PackedRaster</code> to Buffered Image for 24bit over four bytes</p>