在实现alphablend 透明位图时,搞不清楚HDC的关系了
对于下面这个方法,应该如何得到hdcDest和hdcSrc.(概念不是很清除)
AlphaBlend(
HDC hdcDest,
int nXOriginDest,
int nYOriginDest,
int nWidthDest,
int hHeightDest,
HDC hdcSrc,
int nXOriginSrc,
int nYOriginSrc,
int nWidthSrc,
int nHeightSrc,
BLENDFUNCTION blendFunction
);
顺便问一下,该方法里面的那些个int型的参数必须按照要求填么?我的意思是大小啊,坐标啊可不可以自己随便改改。
问题点数:50、回复次数:4Top
1 楼dirdirdir3(风)回复于 2005-08-03 09:59:20 得分 25
可以随便添,hdc可以从你的bmp的CDC中得到。
如bmp1,与bmp2叠加。
c1,c2是生成的CDC,
c1.SelectObject(&bmp1);
c2.SelectObject(&bmp2);
AlphaBlend(c1.m_hdc,0,0,n,m,c2.m_hdc,0,0,n,m,SRCCOPY)Top
2 楼honker110(honker)回复于 2005-08-03 09:59:35 得分 25
hdcDest是你要在其上画图的DC,比如屏幕hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL); 、窗口hdc = ::GetDC(hWnd);
hdcSrc是来源DC,也可以是屏幕、窗口,也可以自己建,然后把位图选进去或自己画,
下面是MSDN抓屏幕的例子
// Create a normal DC and a memory DC for the entire screen. The
// normal DC provides a "snapshot" of the screen contents. The
// memory DC keeps a copy of this "snapshot" in the associated
// bitmap.
hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
hdcCompatible = CreateCompatibleDC(hdcScreen);
// Create a compatible bitmap for hdcScreen.
hbmScreen = CreateCompatibleBitmap(hdcScreen,
GetDeviceCaps(hdcScreen, HORZRES),
GetDeviceCaps(hdcScreen, VERTRES));
if (hbmScreen == 0)
errhandler("hbmScreen", hwnd);
// Select the bitmaps into the compatible DC.
if (!SelectObject(hdcCompatible, hbmScreen))
errhandler("Compatible Bitmap Selection", hwnd);
// Hide the application window.
ShowWindow(hwnd, SW_HIDE);
//Copy color data for the entire display into a
//bitmap that is selected into a compatible DC.
if (!BitBlt(hdcCompatible,
0,0,
bmp.bmWidth, bmp.bmHeight,
hdcScreen,
0,0,
SRCCOPY))
errhandler("Screen to Compat Blt Failed", hwnd);
// Redraw the application window.
ShowWindow(hwnd, SW_SHOW);Top
3 楼honker110(honker)回复于 2005-08-03 10:01:23 得分 0
int参数当然是控制截取或画哪一部分/位置了Top
4 楼yoogle(离谱)回复于 2005-08-03 10:36:34 得分 0
看看我下面这样写行不行?
CDC* m_pdcMemory;
HDC hDC;
hDC = ::GetDC(this->GetSafeHwnd());
BLENDFUNCTION bf;
CBitmap btmp ;
btmp.LoadBitmap(IDB_BITMAP1);
m_pdcMemory->SelectObject(btmp);
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 0x7f; // half of 0xff = 50% transparency
bf.AlphaFormat = 0; // ignore source alpha channel
AlphaBlend(hDC, 100, -100,
100, 100,
m_pdcMemory->m_hDC, 0, 0, 100, 100, bf);
DeleteDC(hDC);
我的selectobject怎么老出错。Top




