两种方法:
当做二进制数据。这样可以将任何文件加入资源,但需要自己解码显示(或者GDI+)
新建bitmap位图,然后将jpg使用图片编辑器打开,全选,复制,粘贴到bitmap
具体步骤如下: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
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)