private void createImage(int w, int h) {
    if (w == 0 || h == 0) return;
    WritableRaster wr;
    if (cm instanceof IndexColorModel)
      wr = ((IndexColorModel)cm).createCompatibleWritableRaster(w, h);
    else
      wr = ((DirectColorModel)cm).createCompatibleWritableRaster(w, h);
    image = new BufferedImage(cm, wr, true, null);
    SampleModel sm = image.getSampleModel();
    if (sm instanceof SinglePixelPackedSampleModel) {
      stride_ = ((SinglePixelPackedSampleModel)sm).getScanlineStride();
    } else {
      stride_ = sm.getWidth();
    }
    db = wr.getDataBuffer();
    if (sm.getTransferType() == DataBuffer.TYPE_INT)
      data = (Object)((DataBufferInt)db).getData();
    else if (sm.getTransferType() == DataBuffer.TYPE_BYTE)
      data = (Object)((DataBufferByte)db).getData();
    else if (sm.getTransferType() == DataBuffer.TYPE_USHORT)
      data = (Object)((DataBufferUShort)db).getData();
    else
      throw new ErrorException("Unsupported pixel type");
  }