title: With BufferedImages, when creating a WritableRaster how do you ensure that it will be compatible with the specific ColorModel?
body: <p>I'm learning to use BufferedImages in java, and am trying to create an animation where each frame of the animation is the result of mathematically fiddling around with pixel data. I'm just playing around really. Originally I was using an indexed ColorModel, but I've changed it (to take advantage of more colors) to a direct ColorModel. But now an error crops up saying -</p>
  
  <p>Raster sun.awt.image.SunWritableRaster@29c204 is incompatible with ColorModel DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000</p>
  
  <p>The code I was using to create the BufferedImage and WriteableRaster is here:</p>
  
  <pre><code>public void initialize(){
      int width = getSize().width;
      int height = getSize().height;
      data = new int [width * height];
  
      DataBuffer db = new DataBufferInt(data,height * width);
      WritableRaster wr = Raster.createPackedRaster(db,width,height,1,null);
      image = new BufferedImage(ColorModel.getRGBdefault(),wr,false,null);
      image.setRGB(0, 0, width, height, data, 0, width);
  }
  </code></pre>