16,471
社区成员
发帖
与我相关
我的任务
分享
HBITMAP hBitmap;
CFile file;
if( !file.Open( m_PathName, CFile::modeRead) )
return ;
BITMAPFILEHEADER bmfHeader;
//读位图文件头信息
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
return ;
//判断是否是BMP
if (bmfHeader.bfType != ((WORD) ('M' << 8) | 'B'))
return ;
//读位图头信息
BITMAPINFOHEADER bmiHeader;
if (file.Read((LPSTR)&bmiHeader, sizeof(bmiHeader)) !=sizeof(bmiHeader))
return ;
//获得大小信息,并显示
int bmWidth=bmiHeader.biWidth;
int bmHeight=bmiHeader.biHeight;
int kw=rect.Width();
int kh=rect.Height();
//计算显示大小
if(bmWidth>bmHeight)
{
double kh1=(double)bmHeight*kw/bmWidth;
kh=(int)kh1;
}
else{
double kw1=(double)bmWidth*kh/bmHeight;
kw=(int)kw1;
}
file.Close();
//获取显示大小的图片
hBitmap = (HBITMAP)LoadImage(
AfxGetInstanceHandle(),
m_PathName,
IMAGE_BITMAP,
kw,
kh,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
pStatic->ModifyStyle(0xF, SS_BITMAP|SS_CENTERIMAGE);
pStatic->SetBitmap(hBitmap);