}
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);
{
// write BitmapFileHeader
os.write(0x42); // B, Windows 3.1x, 95, NT, Bitmap
os.write(0x4d); // M
int filesize = BITMAP_FILE_HEADER_SIZE + BITMAP_INFO_HEADER_SIZE + // header size
4 * writer.getPaletteSize() + //palette size in bytes
imagedata.length;
bos.write4Bytes(filesize);
bos.write4Bytes(0); // reserved
bos.write4Bytes(BITMAP_FILE_HEADER_SIZE + BITMAP_INFO_HEADER_SIZE
+ 4 * writer.getPaletteSize()); // Bitmap Data Offset
}
int width = src.getWidth();
int height = src.getHeight();
{ // write BitmapInfoHeader
bos.write4Bytes(BITMAP_INFO_HEADER_SIZE); // Bitmap Info Header Size
bos.write4Bytes(width); // width
bos.write4Bytes(height); // height
bos.write2Bytes(1); // Number of Planes
bos.write2Bytes(writer.getBitsPerPixel()); // Bits Per Pixel
bos.write4Bytes(0); // Compression
bos.write4Bytes(imagedata.length); // Bitmap Data Size
bos.write4Bytes(0); // HResolution
bos.write4Bytes(0); // VResolution
bos.write4Bytes(0); // Colors
bos.write4Bytes(0); // Important Colors
// bos.write_4_bytes(0); // Compression
}
{ // write Palette
writer.writePalette(bos);
}
{ // write Image Data
bos.writeByteArray(imagedata);
}
}