Created
November 24, 2016 09:51
-
-
Save moi90/77f8d3217b4f899f8ed1f6f8d8f3fc5b to your computer and use it in GitHub Desktop.
Save an image consisting of unsigned chars to a pgm file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void write_pgm(unsigned short id, unsigned char *buf, int width, int height) { | |
char filename[1024]; | |
sprintf(filename, "%simage_%d.pgm", destinationPrefix, id); | |
FILE *fp = fopen(filename, "wb"); | |
if (fp) { | |
fprintf(fp, "P5\n%d %d\n%d\n", width, height, 0xFF); | |
fwrite(buf, width * height, 1, fp); | |
fclose(fp); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment