gbmpc51.cpp

来自「获取BMP位图文件信息的C程序」· C++ 代码 · 共 54 行

CPP
54
字号
#include <stdio.h>
#include <process.h>
#include <io.h>
int main(int argc,char *argv[])
{
	FILE *fp, *fout;
	char ftext[10]="bmpt.txt";
	unsigned int i, j;
	unsigned char c;
	int blank;
	long int total,records, bmpw, realw;

	if(argc!=2){
	   printf("No File Name!\n");
	   exit(1);
	}
	if( (fp=fopen(argv[1],"rb"))==NULL){     //r+b very important
	   printf("Not Find %s!\n",argv[1]);
	   exit(1);
	}
	if( (fout=fopen(ftext,"wt"))==NULL){     //r+b very important
	   printf("Cannot open file!\n");
	   exit(1);
	}
	rewind(fp);
	fseek(fp, 18, 1);  //bmp width
	fread(&bmpw, 4, 1, fp);
	realw=(bmpw/32)*32;
	if (bmpw%32) realw = realw+32;
	rewind(fp);
	fseek(fp,62L,1); //head file is 3EH
	i=0; j=0;
	while (!feof(fp))
	{
		c=fgetc(fp);
		if (j<bmpw/8)
		{
			c=~c;
			fprintf(fout, " 0x%02x,", c);
			i++;
			if (i>=10)
			{
				fprintf(fout, "\n");
				i=0;
			}
		}
		j++;
		if (j>=realw/8) j=0;
	};
	printf("Bmp data in bmpt.txt!\n");
	fclose(fp);
	fclose(fout);
	return 1;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?