Binary data to bitmap
Reading Binary as a Bitmap
Every bitmap image is stored as a long sequence of binary values. To convert that sequence back into a visible image, you must know the image dimensions (width and height in pixels), the colour depth (how many bits represent each pixel), and the colour key that maps each binary value to a colour. Without all three, the binary data cannot be interpreted correctly.
The Four-Step Process
- Determine the colour depth. This tells you how many bits form one pixel (e.g. 1 bit per pixel, 2 bits per pixel).
- Split the binary stream into groups. Read the full bit sequence left to right and divide it into consecutive groups of that many bits. Each group represents exactly one pixel.
- Map each group to a colour using the colour key provided. Every possible bit pattern of that length corresponds to one colour.
- Place the pixels in the grid. Fill the first row left to right with the first set of pixel values, then move to the next row, and so on, until all pixels are placed.
The order is always left to right, top to bottom - the same direction in which English text is read. Missing a group or miscounting the bits will shift every subsequent pixel and corrupt the image from that point onwards.
Worked Examples
1-Bit Colour Depth
Image dimensions: 4 × 4 pixels. Colour depth: 1 bit per pixel.
Colour key: 0 = white, 1 = black.
Binary stream: 0110100101101001
Split into groups of 1 (one bit per pixel), fill the grid row by row:
2-Bit Colour Depth
Image dimensions: 4 × 4 pixels. Colour depth: 2 bits per pixel.
Colour key: 00 = white, 01 = light grey, 10 = dark grey, 11 = black.
Binary stream: 1101011101000001000011010111
Split into groups of 2 (two bits per pixel), fill row by row:
The frame/border pattern emerges clearly because the corner and edge values (11 and 01) surround the white interior (00).
Key Takeaways
- To convert binary data into a bitmap, you must know the image dimensions, the colour depth, and the colour key.
- Group the binary stream into consecutive chunks whose size equals the colour depth - each chunk represents exactly one pixel.
- Pixels are placed left to right, top to bottom in the grid. Miscounting a group shifts every pixel from that point onwards.
- A higher colour depth means larger groups and more possible colours, but the process of splitting and mapping is identical regardless of depth.