bmp文件的结构如下:
typedef struct//BMP文件的文件头
{
char bfType[2]
long bfSize
int bfReserved1
int bfReserved2
long bfOffBits
}BMPHEAD
typedef struct//点位图信息
{
long biSize
long biWidth
long biHeight
int biPlanes
int biBitCount
long biCompress
long biSizeImage
long biXPelsPerMeter
long biYPelsPerMeter
long biClrUsed
long biClrImportant
}BMPINFO
typedef struct//颜色表
{ unsigned char blue
unsigned char green
unsigned char red
unsigned char reaserved
}RGB
bmp文件保存时,先存上面的三个结构体的数据,之后是图像数据.具体信息可查相关书籍
FileName=fileDlg.GetFileName ()FILE *fp=fopen(FileName,"rb")//二进制读方式打开指定的图像文件fread(&FileHead, sizeof(BITMAPFILEHEADER), 1,fp)//读取文件头,文件指针自动后移fread(&InfoHead, sizeof(BITMAPINFOHEADER), 1,fp)//读取信息头,文件指针自动后移//获取图像宽、高、每像素所占位数等信息bmpWidth = InfoHead.biWidthbmpHeight = InfoHead.biHeight//下面完成图像数据向内存数组的存储ImageData=new unsigned char*[bmpHeight]if(InfoHead.biBitCount==24){for (int i=0i<bmpHeighti++){ImageData[i]=new unsigned char[(bmpWidth*3+3)/4*4]}for (int k=0k<bmpHeightk++ ){for(int j=0j<(bmpWidth*3+3)/4*4j++){fread(&ImageData[k][j],1,1,fp)//上面完成动态二维数组的申请,这里实际读取图像数据}}fclose(fp)//关闭文件