m_pBmpFileHeader=(BITMAPFILEHEADER*) new char [sizeof(BITMAPFILEHEADER)];//给文件信息头分配内存
bitmapFile.Read(m_pBmpFileHeader,sizeof(BITMAPFILEHEADER));//读入文件信息头信息
m_pBmpInfoHeader=(BITMAPINFOHEADER*) new char [sizeof(BITMAPINFOHEADER)];//给BMP信息头分配内存
bitmapFile.Read(m_pBmpInfoHeader,sizeof(BITMAPINFOHEADER));
if(m_pBmpFileHeader->bfType!=0x4D42)//判断文件是不是位图文件
{
AfxMessageBox("This is not a bitmap file!!");
bFileRead=FALSE;
bitmapFile.Close();
return;
}
if(m_pBmpInfoHeader->biCompression!=0)//判断图像是不是压缩的
{
AfxMessageBox("This system only support Un-compression!!");
bitmapFile.Close();
return;
}
switch(m_pBmpInfoHeader->biBitCount)//判断颜色的位数
{
case 1:
nPaletteSize=2;
break;
case 4:
nPaletteSize=16;
break;
case 8:
nPaletteSize=256;
break;
case 24:
nPaletteSize=0;//当为真彩色时没有颜色表,所以为0
break;
default:
AfxMessageBox("This color is not valid!!");
bitmapFile.Close();
return;
}