I have an array of raw bytes and I want to make a bmp file from those bytes. That is, I have to fill bitmap header structre and other things, then write down the bytes so I have a bmp file in the proper format.
As I need this for some quick check only, I wonder if there is a portable method to do this – take raw bytes and save them as a bmp file. Any Windows version won’t do as I’m writing that on Unix.
Alternatively, I can save those bytes as any other image format – I only need to have a quick look at the resulting picture.
The following will give you a .ppm image from a byte array. The
"P6"specifies binary format 3 byte per pixel, but plain text is also supported and various forms of grayscale. The reason you should use this is that it is easy as can be and most *nix systems have a bunch of ppmto*-tools: ppmtobmp, ppmtojpeg, …, ppmtopng… you name it.There is also ppmtocad… who would have guessed?