📄 subject_17304.htm
字号:
<p>
序号:17304 发表者:cmoth 发表日期:2002-10-10 11:05:33
<br>主题:为什么在内存中作的图都是黑白的?
<br>内容:我用下面的代码创建的内存设备环境:<BR><BR> CDC TempDC;<BR> TempDC.CreateCompatibleDC (pDC); <BR><BR> CBitmap TempBmp;<BR> CRect TempRect;<BR> GetClientRect(&TempRect);<BR> TempBmp.CreateCompatibleBitmap(&TempDC,TempRect.Width (),TempRect.Height ());<BR> TempDC.SelectObject (TempBmp);<BR><BR>如果在pDC上作图就正常,但在TempDC上作完图,然后用BitBlt函数拷贝到pDC上,总是黑白的,这是什么原因啊?<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:徐景周 回复日期:2002-10-10 11:17:15
<br>内容:参看一下:<BR>BOOL CRectToJpeg::CopyRectToBmp(<BR> CDC* pDC,<BR> CRect* pRectTgt,<BR> CBitmap* pBmp)<BR>{<BR> CDC memDC;<BR> CRect rectCli;<BR><BR> rectCli = *pRectTgt;<BR><BR> CRect rectN = rectCli;<BR> rectN.NormalizeRect();<BR><BR> //Need to adjust width and height a tad:<BR> //Try dividing by 0.96<BR> int tW = (int)((double)rectN.Width() /0.96);<BR> int tH = (int)((double)rectN.Height()/0.96);<BR><BR> rectCli.SetRect(rectCli.TopLeft().x,<BR> rectCli.TopLeft().y,<BR> rectCli.TopLeft().x+tW,<BR> rectCli.TopLeft().y-tH);<BR><BR> //Convert to DP<BR> pDC->LPtoDP(&rectCli);<BR><BR> //Make sure you are in a known mode<BR> int nOldMode = pDC->SetMapMode(MM_TEXT);<BR><BR> if (!memDC.CreateCompatibleDC(pDC))<BR> {<BR> m_csMsg = "Failed to create compatible dc";<BR> pDC->SetMapMode(nOldMode);<BR> return FALSE;<BR> }<BR><BR> int w = abs(rectCli.BottomRight().x - rectCli.TopLeft().x);<BR> int h = abs(rectCli.BottomRight().y - rectCli.TopLeft().y);<BR> int x = rectCli.TopLeft().x;<BR> int y = rectCli.TopLeft().y;<BR><BR> //Create bitmap of desired height and width<BR> if (!pBmp->CreateCompatibleBitmap(pDC,w,h))<BR> {<BR> m_csMsg = "Failed to create compatible bitmap";<BR><BR> pDC->SetMapMode(nOldMode);<BR> pBmp->DeleteObject();<BR> return FALSE;<BR> }<BR><BR> CBitmap* pOrigBmp = memDC.SelectObject(pBmp);<BR><BR> //Do a stretchblt here<BR> if (!memDC.StretchBlt(<BR> 0,<BR> 0,<BR>// tW,<BR>// tH,<BR> w, //复制源图真实尺寸,不拉大。jingzhou xu<BR> h,<BR> pDC,<BR> x,<BR> y, <BR> w,<BR> h,<BR> SRCCOPY))<BR> {<BR> m_csMsg = "Failed to do bitblt into memory DC";<BR> pDC->SetMapMode(nOldMode);<BR> pBmp->DeleteObject();<BR> return FALSE;<BR> }<BR><BR> pDC->SetMapMode(nOldMode);<BR><BR> memDC.SelectObject(pOrigBmp);<BR><BR> return TRUE;<BR>}
<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 + -