VC 怎么显示GIF ?

xiaorou00 2002-07-27 12:36:13
VC 怎么显示GIF ?
...全文
65 点赞 收藏 2
写回复
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
studentforever 2002-07-30
在VC下显示JPEG、GIF格式图像的一种简便方法
http://www.ccw.com.cn/htm/app/aprog/01_7_27_2.asp
回复
dirboy_tym 2002-07-30
/**********************
picName = 文件名
dc = 目标设备句柄
w, h = 目标设备句柄的 长和宽
**********************/
BOOL LoadPic(const char *picName, CDC &dc, DWORD w, DWORD h)
{
IPicture *pPic;
IStream *pStm;

CFileStatus fstatus;
CFile file;
LONG cb;

if (file.Open(picName,CFile::modeRead)&&
file.GetStatus(picName, 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);

DWORD fX, fY;

fX = (DWORD)((double)dc.GetDeviceCaps(HORZRES)*(double)hmWidth/
((double)dc.GetDeviceCaps(HORZSIZE)*100.0) * 1.512f);
fY = (DWORD)((double)dc.GetDeviceCaps(VERTRES)*(double)hmHeight/
((double)dc.GetDeviceCaps(VERTSIZE)*100.0) * 1.512f);

DWORD top=0, left=0;
if (w!=0 && h!=0)
{
if (fX >= w)
fX = w;
else
left = (w-fX)/2;
if (fY >= h)
fY = h;
else
top = (h-fY)/2;
}
if(FAILED(pPic->Render(dc,left,top,fX,fY,0,hmHeight,hmWidth,-hmHeight,NULL)))
{
#ifdef _DEBUG
TRACE("\nFailed To Render The picture!");
#endif
return FALSE;
}
pPic->Release();
}
else
{
#ifdef _DEBUG
TRACE("\nError Loading Picture From Stream!");
#endif
return FALSE;
}
}
}
}
else
{
#ifdef _DEBUG
TRACE("\nCan't Open Image File!");
#endif
return FALSE;
}

return TRUE;
}
这个函数可以显示gif,bmp,jpg图片
如:LoadPic(_T("a.gif",dc,rect.Width(),rect.Height())
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告
暂无公告