Byte Array to Bitmap Converter
Convert raw byte arrays (decimal, hex, base64) to bitmap images. Supports 1-bit, 8-bit, 24-bit, 32-bit color depths with PNG and BMP export.
About
Raw byte data represents pixel information in its most fundamental form: sequential octets encoding color channels per the selected bit depth. Misinterpreting byte order, row padding, or channel count produces corrupted output. A 640×480 image at 24-bit depth requires exactly 921,600 bytes (3 bytes per pixel). The BMP format adds row padding to align each scanline to 4-byte boundaries. Omitting this padding shifts every subsequent row. This tool parses decimal, hexadecimal, base64, and JSON array inputs, maps bytes to RGBA pixel data at the correct stride, and exports standards-compliant BMP files with proper BITMAPINFOHEADER structures or lossless PNG via Canvas.
The converter auto-detects optimal image dimensions from byte count when width is unspecified. It factors the total pixel count and selects the pair of factors closest to a 1:1 aspect ratio. For incomplete final rows the tool zero-pads remaining bytes. Note: this tool assumes linear byte order (no embedded headers or compression). If your source data contains file headers, strip them before conversion.
Formulas
The total byte count required for an uncompressed bitmap is determined by color depth and dimensions:
Where B = total bytes, W = width in pixels, H = height in pixels, D = bit depth (1, 8, 24, or 32).
BMP row padding ensures each scanline aligns to a 4-byte boundary:
Where P = padding bytes appended to each row. For 32-bit images, P is always 0 since 4 bytes per pixel inherently aligns.
Auto-dimension detection finds integer factor pair (w, h) of total pixel count N that minimizes:
BMP file size calculation:
Where ColorTable = 0 for 24/32-bit, 1024 bytes (256 × 4) for 8-bit, and 8 bytes (2 × 4) for 1-bit.
Reference Data
| Color Depth | Bytes/Pixel | Channels | Total Colors | Use Case | Row Padding Rule |
|---|---|---|---|---|---|
| 1-bit Monochrome | 0.125 | 1 (packed) | 2 | Barcodes, QR masks | Pad to 4-byte boundary |
| 8-bit Grayscale | 1 | 1 | 256 | Medical imaging, heightmaps | Pad to 4-byte boundary |
| 16-bit RGB555 | 2 | 3 (packed) | 32,768 | Legacy displays, embedded | Pad to 4-byte boundary |
| 24-bit RGB | 3 | 3 (R, G, B) | 16,777,216 | Photos, standard graphics | Pad to 4-byte boundary |
| 32-bit RGBA | 4 | 4 (R, G, B, A) | 4,294,967,296 | Transparency, compositing | No padding needed (already aligned) |
| BMP File Structure | |||||
| BITMAPFILEHEADER | 14 bytes | Signature (0x42 0x4D = "BM"), file size, data offset | |||
| BITMAPINFOHEADER | 40 bytes | Width, height, bit depth, compression, image size | |||
| Color Table | Variable | Required for ≤ 8-bit. 4 bytes per entry (B, G, R, 0x00) | |||
| Pixel Data | Variable | Bottom-up row order, BGR channel order | |||
| Common Input Formats | |||||
| Decimal CSV | 255, 128, 0, 255, 0, 128 | ||||
| Hex (0x prefix) | 0xFF, 0x80, 0x00, 0xFF, 0x00, 0x80 | ||||
| Hex (plain) | FF 80 00 FF 00 80 | ||||
| JSON Array | [255, 128, 0, 255, 0, 128] | ||||
| Base64 | /4AAgACA (binary encoded) | ||||
| C-style Array | {0xFF, 0x80, 0x00} | ||||
| Dimension Auto-Detection | |||||
| 100 pixels | 10 × 10 | Perfect square | |||
| 1920 pixels | 48 × 40 | Closest factors to square | |||
| 307,200 pixels | 640 × 480 | VGA resolution | |||
| 2,073,600 pixels | 1920 × 1080 | Full HD | |||