湖濱散記部落格的樹心幽徑[login][主頁]
351:20170504用C設計的SavePGM()與SavePBM()影像存檔函數

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);
}


select id,article_id,topic,text from lt_articles_text where article_id =351; ok. update lt_articles set num_reads=num_reads +1 where id=351; ok.