配置mfc窗口
搭建两个picture control
双击开始按钮,输入下面代码
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("bmp(*.bmp)|*.bmp||"), this);
if (dlg.DoModal() != IDOK)
{
MessageBox(_T("图片打开失败"));
return;
}
m_strSrcBmpPath = dlg.GetPathName();
CFile file;
file.Open(m_strSrcBmpPath, CFile::modeRead);
file.Read(m_pBmpFileHeader, 14);
file.Seek(14, CFile::begin);
file.Read(m_pBmpInfo, 40 + 256 * 4);
if (m_pBmpInfo->bmiHeader.biBitCount == 8)//灰度图像,有调色板
{
file.Seek(14 + 40 + 256 * 4, CFile::begin);
}
else if (m_pBmpInfo->bmiHeader.biBitCount == 24)//彩色图像,无调色板
{
file.Seek(14 + 40, CFile::begin);
}
int iWidth = m_pBmpInfo->bmiHeader.biWidth;
int iHeight = m_pBmpInfo->bmiHeader.biHeight;
int iImgSize = m_pBmpInfo->bmiHeader.biSizeImage;
int iXPels = m_pBmpInfo->bmiHeader.biXPelsPerMeter;
int iYPels = m_pBmpInfo->bmiHeader.biYPelsPerMeter;
int biClrUsed = m_pBmpInfo->bmiHeader.biClrUsed;
int biClrImportant = m_pBmpInfo->bmiHeader.biClrImportant;
file.Read(m_pSrcBuf, m_pBmpInfo->bmiHeader.biSizeImage);
file.Close();
Invalidate();