SimplePalette palette = new PaletteFactory()
.makePaletteSimple(src, 256);
BMPWriter writer = null;
if (palette == null)
writer = new BMPWriterRGB();
else
writer = new BMPWriterPalette(palette);
byte imagedata[] = writer.getImageData(src);
BinaryOutputStream bos = new BinaryOutputStream(os, BYTE_ORDER_INTEL);