c - Saving numerical 2D array to image -
lately have been doing numerical method programming in c. bug fixing , throubleshooting it's nice have visual representation of happening. far have been outputting areas of array standard output, doesn't give information. have been playing around bit gnuplot, can't save image, not coordinate system , other stuff.
so looking tutorial or maybe library show me how save array c image, nice possible save color images. transformation numerical value color not problem, can calculate that. nice of point me in direction of useful libraries in field.
best regards
you use .ppm file format... it's simple no library necessary...
file *f = fopen("out.ppm", "wb"); fprintf(f, "p6\n%i %i 255\n", width, height); (int y=0; y<height; y++) { (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);
Comments
Post a Comment