#include <windows.h> #include <stdio.h> unsigned char *pBmpBuf;//读入图像的数据指针 int bmpWidth;//图像的宽 int bmpHeight;//图像的高 RGBQUAD *pColorTable;//颜色表指针 int biBitCount;//图像类型,每像素的位数 bool readBmp(char *bmpName) { //二进制方式打开 FILE *fp=fopen(bmpName,"rb"); if(fp==0) return 0; //跳过位图文件头结构BITMAPFILEHEADER fseek(fp,sizeof(BITMAPFILEHEADER),0); //定义位图头结构变量,读取位图信息头进内存放在变量head中 BITMAPINFOHEADER head; fread(&head,sizeof(BITMAPINFOHEADER),1,fp); bmpWidth=head.biWidth; bmpHeight=head.biHeight; biBitCount=head.biBitCount; //定义变量计算图像每行像素所占的字节数 int lineByte=(bmpWidth * biBitCount/8+3)/4*4; //灰度图像有颜色表,且颜色表表项为256 if(biBitCount==8){ //申请颜色表所需的空间,读颜色表进内存 pColorTable=new RGBQUAD[256]; fread(pColorTable,sizeof(RGBQUAD),256,fp); } //申请位图数据所需的空间,读位图数据进内存 pBmpBuf=new unsigned char[lineByte * bmpHeight]; fr