BGR to PNG Converter
Convert raw BGR and BGRA binary image files to PNG format online. Specify width, height, and bit depth for accurate pixel-level conversion.
About
Raw BGR files store pixel data in Blue-Green-Red byte order without any header, compression, or metadata. This format appears in OpenCV dumps (cv::imwrite with raw flags), embedded camera frame buffers, and legacy Windows DIB sections where the channel order is reversed relative to the standard RGB model. Without specifying exact width, height, and bpp (bits per pixel), the binary blob is uninterpretable. Getting the dimensions wrong produces a garbled, skewed image that wastes debugging time. This tool performs real byte-level channel swapping (B โ R) and encodes the result as a lossless PNG.
The converter validates that file size matches the expected buffer length: W ร H ร 3 for 24-bit BGR or W ร H ร 4 for 32-bit BGRA. Mismatched sizes are rejected before processing. Rows are assumed top-to-bottom, left-to-right with no padding (unlike BMP which pads rows to 4-byte boundaries). If your source adds row padding, pre-strip it before uploading.
Formulas
The raw BGR file contains no header. Every pixel occupies a fixed number of bytes determined by the bit depth. The expected file size must satisfy:
Where W = image width in pixels, H = image height in pixels, and bpp = bits per pixel (24 for BGR, 32 for BGRA).
The channel swap operation for each pixel at linear index i in the source buffer maps to the Canvas RGBA output buffer as follows:
Gout = src[i ร s + 1]
Bout = src[i ร s + 0]
Aout =
Where s = stride in bytes per pixel (3 or 4), and src is the raw Uint8Array buffer. The output is written directly to Canvas ImageData which expects RGBA order, then encoded to PNG via the native canvas.toBlob() method using DEFLATE lossless compression.
Reference Data
| Format | Channel Order | Bytes/Pixel | Alpha | Header | Compression | Common Source |
|---|---|---|---|---|---|---|
| BGR (24-bit) | B, G, R | 3 | No | None | None | OpenCV raw dumps |
| BGRA (32-bit) | B, G, R, A | 4 | Yes | None | None | DirectX surfaces |
| RGB (24-bit) | R, G, B | 3 | No | None | None | PPM P6 payload |
| RGBA (32-bit) | R, G, B, A | 4 | Yes | None | None | Canvas ImageData |
| PNG | R, G, B, A | Variable | Optional | 8-byte signature | DEFLATE (lossless) | Web, screenshots |
| BMP (24-bit) | B, G, R | 3 + padding | No | 54-byte header | Usually none | Windows bitmaps |
| BMP (32-bit) | B, G, R, A | 4 | Yes | 54+ byte header | Usually none | Windows bitmaps |
| TIFF (stripped) | R, G, B | 3 | Optional | IFD header | LZW/ZIP/None | Scanners, GIS |
| YUV 4:2:0 (NV12) | Y, UV interleaved | 1.5 | No | None | None | Video codecs |
| YUV 4:2:2 (YUYV) | Y, U, Y, V packed | 2 | No | None | None | Webcam capture |
| Grayscale (8-bit) | Single channel | 1 | No | None | None | Depth maps |
| BGR565 (16-bit) | B:5 G:6 R:5 | 2 | No | None | None | Embedded LCDs |
| CMYK | C, M, Y, K | 4 | No | Varies | Varies | Print workflows |
| WebP (lossless) | R, G, B, A | Variable | Optional | RIFF header | VP8L (lossless) | Web optimization |