请问如何将位图读入???既从菜单“打开”中选取文件,然后确定,就在视图中显示位图……相信很多人都知道的……如果能给出实现的函数更好了先谢谢了:)
解决方案 »
- CHttpConnection::OpenRequest中的pstrReferer参数是什么?
- 两直线的交点,有什么问题呢?
- 问一个新手的问题
- 特急 请问如何屏蔽这个消息???
- CEdit控件中如何显示char*中的换行?
- 我有个问题,如何在某一路径下建立一个新的文件夹,可能一些人感觉很简单,知道的话一定要跟我说说,加分!谢谢!
- 如何改变ListBox默认滚动条的颜色?
- error C2228: “.FillSampleValues”的左边必须有类/结构/联合
- 一个关于Com的问题,请问如何知道一个已经创建了多少个COM对象???
- 控件难以注册
- 写了个SMS服务,通过网络连接,使用手机模块发短信,可也太慢了啊!!
- 兑现诺言:新贴补分2。
后来不知道放哪去了。
你看看<<Visual C++ 6.0时尚编程百例>>中的[实例 23 位图显示],
那上面有。
我知道如何加载,但我想开始让客户区先为空,然后从菜单“打开”中选取文件,
按“打开”后,显示位图。
我这里有一个是在dialog base程序中的ImgEdit控件显示bmp的,(注释掉的你不要管)。SDI的你看看书就找到了,就是LoadImage、或creatImage然后Bitblt.....
void COcr3Dlg::OnFileLoadImage()
{
int result,len,i;
LPTSTR lpPath,lpExt;
CFileDialog *pFileDlg = new CFileDialog(TRUE);
pFileDlg->m_ofn.lpstrFilter = "BMP FILES\0*.bmp\0TIF FILES\0*.tif\0JPG FILES\0*.JPG\0FAX FILES\0*.fax\0PCX FILES\0*.pcx\0\0";
pFileDlg->m_ofn.lpstrDefExt = "*.bmp";
result = pFileDlg->DoModal();
if( result == IDOK )
{
m_strImgFileName = pFileDlg->GetPathName();
}
delete pFileDlg;
lpPath = m_strImgFileName.GetBuffer(_MAX_PATH);
m_strImgFileName.ReleaseBuffer();
len = m_strImgFileName.GetLength();
for( i = len-1;i >= 0;i--)
{
if( lpPath[i] == '.' )
break;
}
lpExt = &lpPath[i+1];
if( strstr(_strupr((char*)lpExt),"BMP") )
{
m_bRecogBmp=true;
m_hBitmap=(HBITMAP)::LoadImage(NULL,m_strImgFileName.GetBuffer(_MAX_PATH),
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
m_strImgFileName.ReleaseBuffer();
}
/*else if( strstr(_strupr((char*)lpExt),"TIF") )
{
m_bRecogTif = true;
HLSection *pHLSection = new HLSection();
if( pHLSection->DecodeImage(lpPath) )
{
int nWidth,nHeight,nW,nBytePL;
CBitmap *pBitmap = new CBitmap();
BYTE *pBuf = pHLSection->GetImageBuf();
nWidth = pHLSection->GetImageWidth();
nHeight = pHLSection->GetImageHeight();
pBitmap->CreateBitmap(nWidth,nHeight,1,1,NULL);
nW = nWidth;
if(nW%8)
nW += 8-nW%8;
nBytePL = nW>>3;
//令每行字节数为偶数,否则在显示时将会出现乱屏现象
if( nBytePL%2 )
{
BYTE *pData = new BYTE[(nBytePL+1)*nHeight];
for( int i = 0;i < nHeight;i ++ )
{
for( int j = 0;j < nBytePL;j ++ )
{
pData[i*(nBytePL+1)+j] = pBuf[i*nBytePL+j];
}
pData[i*(nBytePL+1)+nBytePL] = 0;
}
nWidth += 8;
nBytePL += 1;
pBuf = pData;
}
pBitmap->SetBitmapBits(nBytePL*nHeight,pBuf);
m_hBitmap = (HBITMAP)pBitmap->GetSafeHandle();
}
else
{
return;
}
delete pHLSection;
}*/
/*else
{
//other image formats
}*/
m_ImgEdit.SetImage(m_strImgFileName.GetBuffer(_MAX_PATH));
m_strImgFileName.ReleaseBuffer();
m_ImgEdit.Display();
}