Suppose I already read binary data from a binary file, how can I create a BMP image from that binary data?
1 Answer
You can find a definition of the bitmap file format on Wikipedia among other places. Use the struct module to create the necessary headers. Because the format is uncompressed it is very easy to write out. The color information must come in BGR order, bottom line to top line, and each line must be padded with zeros to a multiple of 4 bytes.
Or if you'd rather do it the easy way, PIL knows how to read and write BMP.