BitBlt 贴图后只剩黑白色

woshilaoshiren789 2016-01-25 10:33:12

void CMapData::ReSize(int w,int h)
{
if(w==Width&&h==Height)
return;
CDC myDC ;
CBitmap myMap ,*oldmyMap;
CBrush b;
int ww = w>Width?w:Width ;
int hh = h>Height?h:Height ;
myDC.CreateCompatibleDC(&pDC) ;
myMap.CreateCompatibleBitmap(&pDC,ww,hh) ;
oldmyMap = myDC.SelectObject(&myMap) ;

b.CreateSolidBrush(RGB(0,0,255)) ;
myDC.FillRect(CRect(0,0,ww,hh),&b) ;
myDC.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY) ;/////备份当前绘图


pDC.SelectObject(oldmap) ;
map.DeleteObject() ;

map.CreateCompatibleBitmap(&pDC,w,h) ;
oldmap = pDC.SelectObject(&map) ;

pDC.BitBlt(0,0,w,h,&myDC,0,0,SRCCOPY) ;///恢复到新尺寸的位图;

Width = w ;
Height = h ;
myDC.SelectObject(oldmyMap) ;
myDC.DeleteDC() ;
myMap.DeleteObject() ;
b.DeleteObject() ;

oldPoint = newPoint =CPoint(-1,-1) ;

}
...全文
270 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tingtings324 2016-08-08
  • 打赏
  • 举报
回复
想问问 你那个pDC 是全局的吗 也是个memdc吗 我也遇到这个了 兄台怎么破的?
woshilaoshiren789 2016-01-25
  • 打赏
  • 举报
回复
该函数只是想实现当前pDC上的map的大小。其中pDC,map都是初始化没问题的。
schlafenhamster 2016-01-25
  • 打赏
  • 举报
回复
CClientDC myDC(this) ;
woshilaoshiren789 2016-01-25
  • 打赏
  • 举报
回复
请教各位大婶,代码中没发现有什么问题啊,粘贴后只有黑白色,原图中的彩色没有了。
schlafenhamster 2016-01-25
  • 打赏
  • 举报
回复

void CLeftView::OnDraw(CDC* pDC)
{
	CVC60Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
//
	if(pDoc->GetLeftBitmap())//m_hBmpLeft)
	{// not client rect only !
		SIZE sz=GetTotalSize();
		sz.cx-=10;//gap
		sz.cy-=10;
		CDC memDC;
		memDC.CreateCompatibleDC(pDC);
		HBITMAP hOldBitmap = (HBITMAP)memDC.SelectObject(pDoc->GetLeftBitmap());//m_hBmpLeft);
		pDC->BitBlt(4, 4, sz.cx, sz.cy, &memDC, 0, 0, SRCCOPY);// may bigger then client
		memDC.SelectObject(hOldBitmap);
	}
	else
	{
		pDC->TextOut(10, 10, "Open a 24bits bitmap!");
	}
}
void CLeftView::OnDraw(CDC* pDC)// 这个dc是彩色 DC CDC memDC; memDC.CreateCompatibleDC(pDC); // 这个dc是彩色 DC
woshilaoshiren789 2016-01-25
  • 打赏
  • 举报
回复
没看懂,你是说我不用重新选一个MyMap到MyDC吗?
schlafenhamster 2016-01-25
  • 打赏
  • 举报
回复

virtual BOOL CreateCompatibleDC( CDC* pDC );

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

pDC

A pointer to a device context. If pDC is NULL, the function creates a memory device context that is compatible with the system display.

Remarks

Creates a memory device context that is compatible with the device specified by pDC. A memory device context is a block of memory that represents a display surface. It can be used to prepare images in memory before copying them to the actual device surface of the compatible device.

When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.

When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it.

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧