User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Drop BGR/BGRA file here or click to browse Supports raw binary BGR (24-bit) and BGRA (32-bit) files
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

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.

bgr to png raw image converter bgr converter bgra to png raw pixel data image format converter binary to png

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:

FileSize = W ร— H ร— bpp8

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:

Rout = src[i ร— s + 2]
Gout = src[i ร— s + 1]
Bout = src[i ร— s + 0]
Aout =
{
src[i ร— 4 + 3] if bpp = 32255 if bpp = 24

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

FormatChannel OrderBytes/PixelAlphaHeaderCompressionCommon Source
BGR (24-bit)B, G, R3NoNoneNoneOpenCV raw dumps
BGRA (32-bit)B, G, R, A4YesNoneNoneDirectX surfaces
RGB (24-bit)R, G, B3NoNoneNonePPM P6 payload
RGBA (32-bit)R, G, B, A4YesNoneNoneCanvas ImageData
PNGR, G, B, AVariableOptional8-byte signatureDEFLATE (lossless)Web, screenshots
BMP (24-bit)B, G, R3 + paddingNo54-byte headerUsually noneWindows bitmaps
BMP (32-bit)B, G, R, A4Yes54+ byte headerUsually noneWindows bitmaps
TIFF (stripped)R, G, B3OptionalIFD headerLZW/ZIP/NoneScanners, GIS
YUV 4:2:0 (NV12)Y, UV interleaved1.5NoNoneNoneVideo codecs
YUV 4:2:2 (YUYV)Y, U, Y, V packed2NoNoneNoneWebcam capture
Grayscale (8-bit)Single channel1NoNoneNoneDepth maps
BGR565 (16-bit)B:5 G:6 R:52NoNoneNoneEmbedded LCDs
CMYKC, M, Y, K4NoVariesVariesPrint workflows
WebP (lossless)R, G, B, AVariableOptionalRIFF headerVP8L (lossless)Web optimization

Frequently Asked Questions

Raw BGR files contain no header with dimension metadata. You must know the dimensions from the source application. If unknown, divide the file size by the bytes per pixel (3 for BGR, 4 for BGRA) to get the total pixel count. Then factor that number into plausible Wร—H pairs. For example, a 921,600-byte BGR file could be 640ร—480 (307,200 pixels ร— 3 bytes). The converter shows suggested dimension pairs when the file is loaded to help you identify the correct resolution.
BMP files pad each row to a 4-byte boundary. For a 24-bit image that is 5 pixels wide, each row uses 15 bytes of pixel data plus 1 byte of padding (16 total). This converter assumes zero padding (pure BGR data packed contiguously). If your source adds row padding, the file size will not match W ร— H ร— 3 and the converter will reject it. Strip the padding bytes from each row before uploading, or use the BMP format directly which includes a header for self-description.
The conversion is a direct byte-level channel swap with no color space transformation, gamma correction, or tone mapping applied. Each byte value (0-255) is transferred exactly. The output PNG uses the sRGB color space implicitly (standard for web). If your source BGR data was captured in a linear color space or a custom gamma profile, the PNG will display identically to how the raw data would render in an sRGB viewer. No data is lost or modified beyond the Bโ†”R reorder.
Windows Device-Independent Bitmaps (DIBs) store rows bottom-to-top by default. This converter provides a "Flip Vertically" option that reverses the row order during conversion. Enable it if your source produces bottom-up data. The pixel byte order within each row remains unchanged - only the row sequence is inverted. The resulting PNG will display in correct top-to-bottom orientation.
The converter processes files up to 100 MB in the browser. The maximum supported resolution is 16,384 ร— 16,384 pixels per axis, which is the Canvas element limit in most browsers. For a 32-bit BGRA image at 16,384 ร— 16,384, the raw file would be approximately 1,073,741,824 bytes (1 GB), which exceeds the 100 MB limit. Practically, you can convert images up to roughly 5,000 ร— 5,000 at 32-bit BGRA or 5,700 ร— 5,700 at 24-bit BGR within the size constraint.
Diagonal stripes indicate incorrect width. When the width is wrong, each row starts at the wrong byte offset, causing pixel data to shift progressively across rows. If the image appears as random noise, the bit depth setting (24 vs 32) may be incorrect, causing the parser to misalign channel boundaries. Verify your dimensions match the source exactly. The file size validation formula W ร— H ร— (bpp รท 8) = FileSize helps confirm correct settings.