如何通过读取位图文件显示位图?(不是登陆) rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CString StrFilter="位图文件(*.bmp)|*.bmp|所有文件(*.*)|*.*||"; CFileDialog Dlg(TRUE,NULL,NULL,NULL,StrFilter,this); if(!Dlg.DoModal()==IDOK) return ; CString StrFileName; StrFileName=Dlg.GetPathName(); //BITMAPINFO结构指针 BITMAPINFO* pBmpInfo; //DIB图像数据指针 BYTE* pBmpData; CFile MyFile; if(!MyFile.Open(StrFileName,CFile::modeRead|CFile::typeBinary)) return ; BITMAPFILEHEADER BmpHeader; if(MyFile.Read(&BmpHeader,sizeof(BmpHeader))!=sizeof(BmpHeader)) { AfxMessageBox("读位图文件头出现错误!"); return ; } if(BmpHeader.bfType!=0x4d42) { AfxMessageBox("不是位图文件!"); return ; } BITMAPINFOHEADER BmpInfo; if(MyFile.Read(&BmpInfo,sizeof(BmpInfo))!=sizeof(BmpInfo)) { AfxMessageBox("读取位图信息出现错误!"); return ; } if(BmpInfo.biBitCount!=24) { AfxMessageBox("不是真24色位图,程序暂不支持!"); return ; } pBmpInfo=(BITMAPINFO*)new char[sizeof(BITMAPINFOHEADER)]; if(!pBmpInfo) { AfxMessageBox("内存分配错误!"); return ; } memcpy(pBmpInfo,&BmpInfo,sizeof(BITMAPINFOHEADER)); DWORD dataBytes=BmpHeader.bfSize-BmpHeader.bfOffBits; pBmpData=(BYTE*)new char[dataBytes]; if(!pBmpData) { AfxMessageBox("内存分配错误!"); delete pBmpInfo; return ; } if(MyFile.Read(pBmpData,dataBytes)!=dataBytes) { AfxMessageBox("读位图数据错误!"); delete pBmpInfo; delete pBmpData; return ; } MyFile.Close(); CClientDC *pDC=new CClientDC(this); pDC->SetStretchBltMode(COLORONCOLOR); StretchDIBits(pDC->GetSafeHdc(),0,0,BmpInfo.biWidth,BmpInfo.biHeight,0,0, BmpInfo.biWidth,BmpInfo.biHeight, pBmpData,pBmpInfo,DIB_RGB_COLORS,SRCCOPY); 加载 -〉 bitblt 到指定位置 多线程共享资源处理 关于两个语句的用法。 打印问题,涉及XML.小妹觉得很难解决,请各位哥哥帮忙啊!!!!急!!! 用TAPI3和modem拨入不成功? 如何在视图中加入信息? 在扩展dll里面做了一个对话框,可是怎么总是编译说没有定义IDD 请问在 VC 中如何获得系统时间,并转化成字符串格式。 有关编辑框的问题 动态获得属性值 dialog的问题,谁能回答小弟? 如何获得整幅BMP图象的RGB windows vista 在哪里下载DDK
CFileDialog Dlg(TRUE,NULL,NULL,NULL,StrFilter,this);
if(!Dlg.DoModal()==IDOK)
return ;
CString StrFileName;
StrFileName=Dlg.GetPathName();
//BITMAPINFO结构指针
BITMAPINFO* pBmpInfo;
//DIB图像数据指针
BYTE* pBmpData;
CFile MyFile;
if(!MyFile.Open(StrFileName,CFile::modeRead|CFile::typeBinary))
return ;
BITMAPFILEHEADER BmpHeader;
if(MyFile.Read(&BmpHeader,sizeof(BmpHeader))!=sizeof(BmpHeader))
{
AfxMessageBox("读位图文件头出现错误!");
return ;
}
if(BmpHeader.bfType!=0x4d42)
{
AfxMessageBox("不是位图文件!");
return ;
}
BITMAPINFOHEADER BmpInfo;
if(MyFile.Read(&BmpInfo,sizeof(BmpInfo))!=sizeof(BmpInfo))
{
AfxMessageBox("读取位图信息出现错误!");
return ;
}
if(BmpInfo.biBitCount!=24)
{
AfxMessageBox("不是真24色位图,程序暂不支持!");
return ;
}
pBmpInfo=(BITMAPINFO*)new char[sizeof(BITMAPINFOHEADER)];
if(!pBmpInfo)
{
AfxMessageBox("内存分配错误!");
return ;
}
memcpy(pBmpInfo,&BmpInfo,sizeof(BITMAPINFOHEADER));
DWORD dataBytes=BmpHeader.bfSize-BmpHeader.bfOffBits;
pBmpData=(BYTE*)new char[dataBytes];
if(!pBmpData)
{
AfxMessageBox("内存分配错误!");
delete pBmpInfo;
return ;
}
if(MyFile.Read(pBmpData,dataBytes)!=dataBytes)
{
AfxMessageBox("读位图数据错误!");
delete pBmpInfo;
delete pBmpData;
return ;
}
MyFile.Close();
CClientDC *pDC=new CClientDC(this);
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),0,0,BmpInfo.biWidth,BmpInfo.biHeight,0,0,
BmpInfo.biWidth,BmpInfo.biHeight,
pBmpData,pBmpInfo,DIB_RGB_COLORS,SRCCOPY);