⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_41812.htm

📁 vc
💻 HTM
字号:
<p>
序号:41812 发表者:立山而飞 发表日期:2003-05-29 16:46:16
<br>主题:请教如何利用vc编一个能读取显示图像(bmp、jpeg等只要有一种类型就可以)?
<br>内容:主要是刚刚学习vc,不知道从什么地方下手?请一步步教我?谢谢<BR>只要&nbsp;&nbsp;文件/打开/&nbsp;&nbsp;弹出对话框&nbsp;&nbsp;选择类型 bmp等,然后能够显示就可以了。<BR>就像利用windows自带的画图软件一样,能够打开bmp格式就够了。不胜感激!!
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:luowen 回复日期:2003-05-29 21:40:50
<br>内容:用BITBLT可以显示BMP;<BR>如果要显示JPG,GIF等可以用GDI+类
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:金枪鱼 回复日期:2003-05-29 23:16:24
<br>内容:现存的CPictureEx类,还用自己编。在vchelp中去找吧,同时支持bmp/jpg/gif/cur/ico/动画gif。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:eric 回复日期:2003-05-30 10:35:28
<br>内容:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CDC memDC;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memDC.CreateCompatibleDC(pDC);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HBITMAP hBitmap,hOldBitmap;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CBitmap bitmap;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BITMAP structBitmap;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CSize size;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hBitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),m_strBmpName,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hOldBitmap=(HBITMAP)memDC.SelectObject(hBitmap);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Attach(hBitmap);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.GetBitmap(&amp;structBitmap);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size.cx=structBitmap.bmWidth+40;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size.cy=structBitmap.bmHeight+40;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pDC-&gt;BitBlt(20,20,structBitmap.bmWidth,structBitmap.bmHeight,&amp;memDC,0,0,SRCCOPY);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap.Detach();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;memDC.SelectObject(hOldBitmap);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetScrollSizes(MM_TEXT,size);<BR><BR><BR>如何?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:立山而飞 回复日期:2003-06-05 17:14:26
<br>内容:请问3楼的,代码在哪里加?能不能具体点。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:大笨钟 回复日期:2003-06-06 15:17:05
<br>内容:void CTestDlg::OnButton3() <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: Add your control notification handler code here<BR>&nbsp;&nbsp;&nbsp;&nbsp;CString strPath;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CFileDialog dlg(TRUE,"jpg","*.jpg", <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"JPEG文件(*.jpg)|*.jpg|GIF文件(*.gif)|*.gif||",NULL); <BR>&nbsp;&nbsp;&nbsp;&nbsp;if(dlg.DoModal()==IDOK) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strPath=dlg.GetPathName(); <BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;Invalidate(); <BR>&nbsp;&nbsp;&nbsp;&nbsp;} <BR>//&nbsp;&nbsp;&nbsp;&nbsp;CPaintDC dc(this);<BR>&nbsp;&nbsp;&nbsp;&nbsp;CDC* pDC=this-&gt;GetDC();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;IStream *pStm;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CFileStatus fstatus;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CFile file;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;LONG cb;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;HGLOBAL hGlobal;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (file.Open(strPath,CFile::modeRead)&amp;&amp;file.GetStatus(strPath,fstatus)&amp;&amp; ((cb = fstatus.m_size) != -1))&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hGlobal = GlobalAlloc(GMEM_MOVEABLE, cb);&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LPVOID pvData = NULL;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (hGlobal != NULL)&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((pvData = GlobalLock(hGlobal)) != NULL)&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.ReadHuge(pvData, cb);&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GlobalUnlock(hGlobal);&nbsp;&nbsp;<BR>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&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fX = (double)pDC-&gt;GetDeviceCaps(HORZRES)*(double)hmWidth/((double)pDC-&gt;GetDeviceCaps(HORZSIZE)*100.0);&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fY = (double)pDC-&gt;GetDeviceCaps(VERTRES)*(double)hmHeight/((double)pDC-&gt;GetDeviceCaps(VERTSIZE)*100.0);&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(FAILED(pPic-&gt;Render(*pDC,0,0,(DWORD)fX,(DWORD)fY,0,hmHeight,hmWidth,-hmHeight,NULL)))&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox("渲染图像失败!");&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pPic-&gt;Release();&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;else&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox("从流中装载图像失败!");&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;GlobalFree(hGlobal);<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:立山而飞 回复日期:2003-07-14 11:23:50
<br>内容:楼上的,按这样子是可以显示图像了,可是,最大化的时候,结果就一片空白了,图像不见了。而且,我想要做其他图像处理,比如灰度化等等,这样子好像没有文件头、颜色等,无法实现啊
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:佳明 回复日期:2003-07-16 13:43:36
<br>内容:显示jpg 可以用 ATL中的CImage类<BR><BR>先#include "atlimage.h"<BR><BR>再CImage MyImage;<BR><BR>MyImage.Load("jpg1.jpg"); //把图片载进来<BR>MyImage.Draw(hDestDc,xDest,yDest);//把图片显示出来<BR>用完后 MyImage.Destroy (); //释放<BR><BR>CImage有很多成员函数,Draw 几种形式,上面是最简单的一种<BR><BR>Load一张新图片前先 Destroy() 掉之前的图片
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -