vc中如何获取JPEG格式图像的尺寸?
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
jpg和gif尺寸
CFileDialog dlg(TRUE,"jpg","*.jpg",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"JPEG文件(*.jpg)|*.jpg|GIF文件(*.gif)|*.gif||",NULL);
CString m_Path;
if(dlg.DoModal()==IDOK)
{
m_Path=dlg.GetPathName();
Invalidate();
}
else
{
return;
}
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
LPVOID pvData=NULL;
HGLOBAL hGlobal;
if(file.Open(m_Path,CFile::modeRead)&&file.GetStatus(m_Path,fstatus)&&((cb=fstatus.m_size)!=-1))
{
hGlobal=GlobalAlloc(GMEM_MOVEABLE,cb);
if(hGlobal!=NULL)
{
if((pvData=GlobalLock(hGlobal))!=NULL)
{
file.ReadHuge(pvData,cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal,TRUE,&pStm);
}
}
}
IPicture *pPic;
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth=0;
OLE_YSIZE_HIMETRIC hmHeight=0;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
CDC *p=GetDC();
int lWidthPixels=MulDiv(hmWidth,p->GetDeviceCaps(LOGPIXELSX),2540);
int lHeightPixels=MulDiv(hmHeight,p->GetDeviceCaps(LOGPIXELSY),2540);
CString x;
x.Format("宽度:%d 高度:%d",lWidthPixels,lHeightPixels );
AfxMessageBox(x);
}
GlobalFree(hGlobal);
CFileDialog dlg(TRUE,"jpg","*.jpg",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"JPEG文件(*.jpg)|*.jpg|GIF文件(*.gif)|*.gif||",NULL);
CString m_Path;
if(dlg.DoModal()==IDOK)
{
m_Path=dlg.GetPathName();
Invalidate();
}
else
{
return;
}
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
LPVOID pvData=NULL;
HGLOBAL hGlobal;
if(file.Open(m_Path,CFile::modeRead)&&file.GetStatus(m_Path,fstatus)&&((cb=fstatus.m_size)!=-1))
{
hGlobal=GlobalAlloc(GMEM_MOVEABLE,cb);
if(hGlobal!=NULL)
{
if((pvData=GlobalLock(hGlobal))!=NULL)
{
file.ReadHuge(pvData,cb);
GlobalUnlock(hGlobal);
CreateStreamOnHGlobal(hGlobal,TRUE,&pStm);
}
}
}
IPicture *pPic;
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC hmWidth=0;
OLE_YSIZE_HIMETRIC hmHeight=0;
pPic->get_Width(&hmWidth);
pPic->get_Height(&hmHeight);
CDC *p=GetDC();
int lWidthPixels=MulDiv(hmWidth,p->GetDeviceCaps(LOGPIXELSX),2540);
int lHeightPixels=MulDiv(hmHeight,p->GetDeviceCaps(LOGPIXELSY),2540);
CString x;
x.Format("宽度:%d 高度:%d",lWidthPixels,lHeightPixels );
AfxMessageBox(x);
}
GlobalFree(hGlobal);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询