3个回答
展开全部
具体步骤如下:
1、在dialog面板拖入Edit Box控件,利用ClassWizard关联一个CEdit型控制成员变量m_edit或者在dialog面板拖入Static Text控件,利用ClassWizard关联一个CStatic型成员变量m_picture更好,边界处理更好.
2、编辑显示函数,我在这里添加的是XXXDlg的成员函数,代码如下:
[cpp] view plaincopy
bool CShowJPGStreamDlg::ShowJpgGif(CDC *pDC, CString strPath, int x, int y)
{
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
if (file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&&((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
pvData = GlobalLock(hGlobal);
if (pvData != NULL)
{
file.Read(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
}
}
}
else
return false;
//显示JPEG和GIF格式的图片,GIF只能显示一帧,还不能显示动画,
//要显示动画GIF请使用ACTIVE控//件。
IPicture *pPic;
//load image from file stream
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
double fX,fY;
//get image height and width
fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
//use render function display image
if(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
{
pPic->Release();
return false;
}
pPic->Release();
}
else
return false;
return true;
}
1、在dialog面板拖入Edit Box控件,利用ClassWizard关联一个CEdit型控制成员变量m_edit或者在dialog面板拖入Static Text控件,利用ClassWizard关联一个CStatic型成员变量m_picture更好,边界处理更好.
2、编辑显示函数,我在这里添加的是XXXDlg的成员函数,代码如下:
[cpp] view plaincopy
bool CShowJPGStreamDlg::ShowJpgGif(CDC *pDC, CString strPath, int x, int y)
{
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
if (file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&&((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
pvData = GlobalLock(hGlobal);
if (pvData != NULL)
{
file.Read(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
}
}
}
else
return false;
//显示JPEG和GIF格式的图片,GIF只能显示一帧,还不能显示动画,
//要显示动画GIF请使用ACTIVE控//件。
IPicture *pPic;
//load image from file stream
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
double fX,fY;
//get image height and width
fX = (double)pDC->GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
fY = (double)pDC->GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
//use render function display image
if(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
{
pPic->Release();
return false;
}
pPic->Release();
}
else
return false;
return true;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
插入-》资源-》导入-》选择你要的图片-》起个名(假设为bmp,ID为IDR_BMP1)
在你校显示图片的程序中加入如下代码(比如一个按钮事件中):
CClientDC dc(this);//取得客户区内存DC
CBitmap bitmap;
CBitmap* pOldBitmap;
CDC MemDC;
MemDC.CreateCompatibleDC(&dc); ///建立与显示设备兼容的内存设备场境
bitmap.LoadBitmap(IDB_BITMAP2); ///取出位图资源
pOldBitmap=MemDC.SelectObject(&bitmap); ///将位图选入内存场境
dc.BitBlt(0,0,1000,1000,&MemDC,0,0,SRCCOPY); ///显示它,参数包括坐标及绘图区大小
MemDC.SelectObject(pOldBitmap);
在你校显示图片的程序中加入如下代码(比如一个按钮事件中):
CClientDC dc(this);//取得客户区内存DC
CBitmap bitmap;
CBitmap* pOldBitmap;
CDC MemDC;
MemDC.CreateCompatibleDC(&dc); ///建立与显示设备兼容的内存设备场境
bitmap.LoadBitmap(IDB_BITMAP2); ///取出位图资源
pOldBitmap=MemDC.SelectObject(&bitmap); ///将位图选入内存场境
dc.BitBlt(0,0,1000,1000,&MemDC,0,0,SRCCOPY); ///显示它,参数包括坐标及绘图区大小
MemDC.SelectObject(pOldBitmap);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
CFileDialog fileOpenDlg(TRUE, "bmp", "*.bmp", NULL, "Bitmap Files(*.bmp)", NULL);
int nRespond = fileOpenDlg.DoModal();
if(nRespond == IDOK)
{ CString filePath = fileOpenDlg.GetPathName();
m_pDib = new CDib(filePath);
if(m_pDib->IsValid())
{ SetWindowText(filePath);
drawpicture(); }
else
{ if (m_pDib)
{ delete m_pDib;
m_pDib = NULL;
}
} }
CClientDC dc(this);CDib* pDib = m_pDib;
if(pDib)
{ RefreshWindow();
//获取位图的宽度和高度
m_nWidth = (int)pDib->GetWidth();
m_nHeight = (int)pDib->GetHeight();
//创建设备兼容位图
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOldBitmap = memDC.SelectObject(&m_bitmap);
pDib->Draw(memDC.m_hDC, 1,1, m_nWidth, m_nHeight, 0, 0, m_nWidth, m_nHeight, DIB_RGB_COLORS, SRCCOPY);
int nOldBkMode = memDC.SetBkMode(TRANSPARENT);
dc.BitBlt(0, 0, 800, 600, &memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOldBitmap);
memDC.SetBkMode(nOldBkMode);
}
if(m_bitmap.GetSafeHandle()) m_bitmap.DeleteObject();
CClientDC dc(this);
//创建设备兼容位图
CRect clientRect;
m_img.MoveWindow(CRect(0,0,m_pDib->GetWidth()+3,m_pDib->GetHeight()+3));
m_img.GetClientRect(&clientRect);
m_bitmap.CreateCompatibleBitmap(&dc,clientRect.Width(),clientRect.Height());
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOldBitmap = memDC.SelectObject(&m_bitmap);
memDC.SelectObject(pOldBitmap);
ReleaseDC(&dc);
int nRespond = fileOpenDlg.DoModal();
if(nRespond == IDOK)
{ CString filePath = fileOpenDlg.GetPathName();
m_pDib = new CDib(filePath);
if(m_pDib->IsValid())
{ SetWindowText(filePath);
drawpicture(); }
else
{ if (m_pDib)
{ delete m_pDib;
m_pDib = NULL;
}
} }
CClientDC dc(this);CDib* pDib = m_pDib;
if(pDib)
{ RefreshWindow();
//获取位图的宽度和高度
m_nWidth = (int)pDib->GetWidth();
m_nHeight = (int)pDib->GetHeight();
//创建设备兼容位图
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOldBitmap = memDC.SelectObject(&m_bitmap);
pDib->Draw(memDC.m_hDC, 1,1, m_nWidth, m_nHeight, 0, 0, m_nWidth, m_nHeight, DIB_RGB_COLORS, SRCCOPY);
int nOldBkMode = memDC.SetBkMode(TRANSPARENT);
dc.BitBlt(0, 0, 800, 600, &memDC, 0, 0, SRCCOPY);
memDC.SelectObject(pOldBitmap);
memDC.SetBkMode(nOldBkMode);
}
if(m_bitmap.GetSafeHandle()) m_bitmap.DeleteObject();
CClientDC dc(this);
//创建设备兼容位图
CRect clientRect;
m_img.MoveWindow(CRect(0,0,m_pDib->GetWidth()+3,m_pDib->GetHeight()+3));
m_img.GetClientRect(&clientRect);
m_bitmap.CreateCompatibleBitmap(&dc,clientRect.Width(),clientRect.Height());
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOldBitmap = memDC.SelectObject(&m_bitmap);
memDC.SelectObject(pOldBitmap);
ReleaseDC(&dc);
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |