- 论坛徽章:
- 0
|
使用按字节读取bmp图片转存,但是读取的文件转存后与源图像有差别,请问如何解决?
仅限于256灰度图片
/*按字节读取bmp文件*/
#include<stdio.h>
#define BmpFileHead 54
#define ColorNumber 256
int main(void)
{
int i,j;
FILE *fpout,*fpin;
unsigned char c;
if((fpout = fopen("lena.bmp","r+b")) == NULL)
printf("can't open source file\n");
if((fpin = fopen("copy.bmp","w")) == NULL)
printf("can't open source file\n");
for(i = 0;i != BmpFileHead;i++)
{
c = fgetc(fpout);
fputc(c,fpin);
}
fseek(fpout,BmpFileHead-1,SEEK_SET);
for(i = 0;i != 4 * ColorNumber;i++)
{
c = fgetc(fpout);
fputc(c,fpin);
}
fseek(fpout,1078,SEEK_SET);
for(i = 0;i != 256;i++)
for(j = 0;j != 260;j++)
{
c = fgetc(fpout);
fputc(c,fpin);
}
fclose(fpout);
fclose(fpin);
return 0;
}[img]E:\copy.bmp[/img]
[ 本帖最后由 虑而后能得 于 2009-7-21 12:57 编辑 ] |
|