資源簡介
在linux環(huán)境下讀取圖像,并且將256x256圖像壓縮成128x128

代碼片段和文件信息
/*?sample.c
/*
/*?The?enclosed?function?reads?in?a?one-byte/pixel?unsigned?char?image?*/
/*?with?filename?in?variable?fn?and?of?size?xsize*ysize??*/?
/*?the?array?data?is?declared?with?the?statement:????*/?
/*?data=(unsigned?char*)calloc(xsize*ysize?sizeof(char));*/?
/*?upon?exiting?cdatainput?data?will?contain?the?input?image?*/?
#include?
int?main()
{
?int?xsizeysize;
?int?ijmn;
?unsigned?char?data[256][256];
?unsigned?char?data2[128][128];
?FILE?*mri_in2?*mri_out2;
?unsigned?char?pixel;
?xsize=255;
?ysize=255;
?mri_in2=fopen(“mri““r“);???/*?open?and?read?image*/
?for?(i=0;?i<=xsize;i++)
???{
?????for?(j=0;j<=ysize;j++)
???????{
?fread(&pixelsizeof(char)1mri_in2);
?data[i][j]=pixel;
???????}
???}
?fclose(mri_in2);
?for?(i=0m=0;?i<=xsize;i=i+2m++)????/*?make?ij?select?one?pixel?escape?one?so?the?size?will?be?reduced?*/?
???{
?????for?(j=0n=0;?j<=ysize;j=j+2n++)
???????{
?data2[m][n]=data[i][j];????
?
???????}
?????
???}
?mri_out2=fopen(“out2““wb“);??????/*?generate?a?new?image?*/
?fwrite(data2sizeof(char)sizeof(data2)mri_out2);
?fclose(mri_out2);
?return(0);
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????1117??2013-02-18?14:10??image?shrink\image?shrink.c
?????目錄??????????0??2013-03-02?15:08??image?shrink
-----------?---------??----------?-----??----
?????????????????1117????????????????????2
評(píng)論
共有 條評(píng)論