itmapInfo.biBitCount!=24)
{
MessageBox("对不起,当前
程序只支持24位位图信息!");
return;
}
bitmapinfo=(BITMAPINFO*)new char[sizeof(BITMAPINFOHEADER)];
if(!bitmapinfo)
{
MessageBox("内存分配失败!");
return;
}
/*把BMP位图信息头中的数据读取到位图信息结构中去.*/
memcpy(bitmapinfo,&BitmapInfo,sizeof(BITMAPINFOHEADER));
/*用来得到位图文件的大小*/
DWORD dataByte=BitmapHead.bfSize-BitmapHead.bfOffBits;
BmpData=(BYTE*)new char[dataByte];
if(!BmpData)
{
MessageBox("内存分配失败!");
delete bitmapinfo;
delete BmpData;
return;
}
if(file.Read(BmpData,dataByte)!=dataByte)
{
MessageBox("读取位图数据失败!");
return;
}
file.Close();
CClientDC *pDC=new CClientDC(this);
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),200,0,BitmapInfo.biWidth,BitmapInfo.biHeight, 0,0,BitmapInfo.biWidth,BitmapInfo.biHeight,BmpData,bitmapinfo,DIB_RGB_COLORS,SRCCOPY);
}
最后给大家介绍两个显示位图的特效的例子更多的特效显示(
http://www.pconline.com.cn/pcedu/empolder/gj/vc/0504/608259.html):
1> 水平交错显示位图
void CListBmap::OnButton1()
{
// TODO: Add your control notification handler code here
HBITMAP hBitmap;
CBitmap cBitmap;
hBitmap=(HBITMAP)::LoadImage(::AfxGetInstanceHandle(),"NetFriend.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
cBitmap.Attach(hBitmap);
cBitmap.GetBitmap(&bitmap);
int i=0,j=0;
CClientDC *pDC=new CClientDC(this);
CDC memDC;
memDC.CreateCompatibleDC(GetDC());
memDC.SelectObject(&cBitmap);
for(i=0;i<bitmap.bmHeight;i+=2)
{
j=i;
while(j>0)
{
pDC->StretchBlt(0,j-1,bitmap.bmWidth,1,&memDC,0,bitmap.bmHeight-(i-j+1), bitmap.bmWidth,1,SRCCOPY);
pDC->StretchBlt(0,bitmap.bmHeight-j,bitmap.bmWidth,1,&memDC,0,i-j, bitmap.bmWidth,1,SRCCOPY);
j-=2;
}
Sleep(50);
}
}
2>雨点显示:
void CListBmap::OnButton2()
{
// TODO: Add your control notification handler code here
HBITMAP hBitmap;
CBitmap cBitmap;
hBitmap=(HBITMAP)::LoadImage(::AfxGetInstanceHandle(),"NetFriend.bmp", IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
cBitmap.Attach(hBitmap);
cBitmap.GetBitmap(&bitmap);
int i=0,j=0;
CClientDC *pDC=new CClientDC(this);
CDC memDC;
memDC.CreateCompatibleDC(GetDC());
memDC.SelectObject(&cBitmap);
for ( i=0; i<=bitmap.bmHeight; i++ )
{
&n