int savePGM(unsigned char *imgb,int width, int height,int maxgray,char *fname) { FILE *outfile; outfile = fopen(fname, "wb"); fprintf(outfile,"P5 %d %d %d ",width,height,maxgray); for (int y=0;y<height;y++){ for (int x=0;x<width;x++){ fprintf(outfile,"%c ",*(imgb+width*y+x)); } fprintf(outfile,"\n"); } fclose(outfile);
}
int savePBM(char *img,int width, int height,char *fname) { FILE *outfile; outfile = fopen(fname, "w"); fprintf(outfile,"P1\n%d %d\n",width,height); for (int y=0;y<height;y++){ for (int x=0;x<width;x++){ fprintf(outfile,"%d",*(img+y*width+x)-'0'); } fprintf(outfile,"\n"); } fclose(outfile); }
|