Saving a 2D numeric array to an image

Recently, I have been doing programming of numerical methods in C. To fix errors and troubleshoot, it's nice to have some kind of visual representation of what is going on. So far, I have outputted areas of the array to standard output, but this does not provide such information. I also played a little with gnuplot, but I can’t get it except for the image and not the coordinate system and everything else.

So, I am looking for a tutorial or perhaps a library to show me how to save an array from c to image, it would be especially nice to save color images. Converting from a numeric value to color is not a problem, I can calculate this. It would be nice if someone pointed me towards some useful libraries in this area.

Best wishes

+6
c image numerical-methods
source share
1 answer

You can use the .ppm file format ... it's so simple that the library is not needed ...

FILE *f = fopen("out.ppm", "wb"); fprintf(f, "P6\n%i %i 255\n", width, height); for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { fputc(red_value, f); // 0 .. 255 fputc(green_value, f); // 0 .. 255 fputc(blue_value, f); // 0 .. 255 } } fclose(f); 
+9
source share

All Articles