好像不能用loadimage的,用IPicture吧,很简单。
给你一个函数,也是以前看到的。 BOOL DrawImg(CString strFile,
CDC *pDC,
CRect rc,
BOOL bStretch)
{
IPicture *pPic;
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
if (file.Open(strFile,CFile::modeRead) &&
file.GetStatus(strFile, fstatus) &&
((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
if ((pvData = GlobalLock(hGlobal)) != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
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;
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);
int left = rc.left;
int top = rc.top;
int width = rc.Width();
int height = rc.Height();
if (bStretch)
{
if (width == 0) width = (int)fX;
if (height == 0) height = (int)fY;
}
else
{
width = (int)fX;
height = (int)fY;
}
if(FAILED(pPic->Render(*pDC,
left,
top,
width,
height,
0,
hmHeight,
hmWidth,
-hmHeight,
NULL)))
{
AfxMessageBox("Failed To Render The picture!");
return FALSE;
}
pPic->Release();
}
else
{
AfxMessageBox("Error Loading Picture From Stream!");
return FALSE;
}
}
}
}
else
{
AfxMessageBox("Can't Open Image File!");
return FALSE;
}
return TRUE;
}
给你一个函数,也是以前看到的。 BOOL DrawImg(CString strFile,
CDC *pDC,
CRect rc,
BOOL bStretch)
{
IPicture *pPic;
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
if (file.Open(strFile,CFile::modeRead) &&
file.GetStatus(strFile, fstatus) &&
((cb = fstatus.m_size) != -1))
{
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);
LPVOID pvData = NULL;
if (hGlobal != NULL)
{
if ((pvData = GlobalLock(hGlobal)) != NULL)
{
file.ReadHuge(pvData, cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal, TRUE, &pStm);
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;
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);
int left = rc.left;
int top = rc.top;
int width = rc.Width();
int height = rc.Height();
if (bStretch)
{
if (width == 0) width = (int)fX;
if (height == 0) height = (int)fY;
}
else
{
width = (int)fX;
height = (int)fY;
}
if(FAILED(pPic->Render(*pDC,
left,
top,
width,
height,
0,
hmHeight,
hmWidth,
-hmHeight,
NULL)))
{
AfxMessageBox("Failed To Render The picture!");
return FALSE;
}
pPic->Release();
}
else
{
AfxMessageBox("Error Loading Picture From Stream!");
return FALSE;
}
}
}
}
else
{
AfxMessageBox("Can't Open Image File!");
return FALSE;
}
return TRUE;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货