I have a data array of pixel intensity (e.g. unsigned char pixel_intensity[4] = {0, 255, 255, 0}
) and I need to create image in C code on Linux (Raspberry Pi).
What is the easiest way to do it?
I have a data array of pixel intensity (e.g. unsigned char pixel_intensity[4] = {0, 255, 255, 0}
) and I need to create image in C code on Linux (Raspberry Pi).
What is the easiest way to do it?
I would suggest using the netpbm format as it is very easy to program. It is documented here and here.
I have written a little demonstration of how to write a simple greyscale ramp to a 100x256 image below.
The header of the image looks like this:
And the image looks like this (I have made it into a JPEG for rendering on here)
Once you have an image, you can use the superb
ImageMagick
(here) tools to convert the image to anything else you like, e.g. if you want the greyscale created by the above converted into a JPEG, just useImageMagick
like this:Or, if you want a PNG
You can actually use the PGM format images directly on the web, by convention, the MIME type is
image/x-portable-graymap