Skip to content

Instantly share code, notes, and snippets.

@moi90
Created November 24, 2016 09:51
Show Gist options
  • Save moi90/77f8d3217b4f899f8ed1f6f8d8f3fc5b to your computer and use it in GitHub Desktop.
Save moi90/77f8d3217b4f899f8ed1f6f8d8f3fc5b to your computer and use it in GitHub Desktop.
Save an image consisting of unsigned chars to a pgm file
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