void CFriendWnd::OnPaint()
{
CPaintDC dc(this);
CDC *memDC = new CDC;
memDC->CreateCompatibleDC( &dc );
CBitmap* bitmap = new CBitmap;
bitmap->LoadBitmap( IDB_BITMAP1 );
memDC->SelectObject( bitmap );
//dc.BitBlt(0,0,100,100,memDC,0,0,SRCCOPY);
TransparentBlt(dc.m_hDC, 0, 0, 100, 100,
memDC->m_hDC, 0, 0, 100, 100, RGB(255,255,255));}为什么运行以后 我的整张图片都透明了啊
{
CPaintDC dc(this);
CDC *memDC = new CDC;
memDC->CreateCompatibleDC( &dc );
CBitmap* bitmap = new CBitmap;
bitmap->LoadBitmap( IDB_BITMAP1 );
memDC->SelectObject( bitmap );
//dc.BitBlt(0,0,100,100,memDC,0,0,SRCCOPY);
TransparentBlt(dc.m_hDC, 0, 0, 100, 100,
memDC->m_hDC, 0, 0, 100, 100, RGB(255,255,255));}为什么运行以后 我的整张图片都透明了啊
解决方案 »
- 想用到ole的功能,是应该import一个dll,还是pragma lib加入一个lib?
- 求使用Grid ActiveX Control的例子
- 我用VC开发环境写的一个ATL COM控件,请问C能够调用此控件吗?
- 如何创建一个不规则形状的窗口
- 请问各位大侠,如果在只有DLL文件,而没有Lib文件,如何调用其中的函数!
- 求教:在在模式对话框BOOL CXXX::OnInitDialog()中InitSocket()初始化失败,怎样退出该模式对话框
- 高分求OCR接口
- 自绘菜单的问题
- 问一个_beginthread的问题
- 关于CString.Format 的e% 输出格式问题
- 祝老朱zhucde生日快乐!散分
- MFC Ext Dll的问题。调用了AfxInitSocket,但是在调用CSocket.Create会出错!
你用BOOL b=TransparentBlt(dc.m_hDC, 0, 0, 100, 100,
memDC->m_hDC, 0, 0, 100, 100, RGB(255,255,255));
调试一下,看看b是TRUE还是FALSE。
int nXOriginDest, // 目标X偏移
int nYOriginDest, // 目标Y偏移
int nWidthDest, // 目标宽度
int nHeightDest, // 目标高度
HDC hdcSrc, // 源DC
int nXOriginSrc, // 源X起点
int nYOriginSrc, // 源Y起点
int nWidthSrc, // 源宽度
int nHeightSrc, // 源高度
UINT crTransparent // 透明色,COLORREF类型
)
{
HBITMAP hOldImageBMP, hImageBMP = CreateCompatibleBitmap(hdcDest, nWidthDest, nHeightDest); // 创建兼容位图
HBITMAP hOldMaskBMP, hMaskBMP = CreateBitmap(nWidthDest, nHeightDest, 1, 1, NULL); // 创建单色掩码位图
HDC hImageDC = CreateCompatibleDC(hdcDest);
HDC hMaskDC = CreateCompatibleDC(hdcDest);
hOldImageBMP = (HBITMAP)SelectObject(hImageDC, hImageBMP);
hOldMaskBMP = (HBITMAP)SelectObject(hMaskDC, hMaskBMP);
// 将源DC中的位图拷贝到临时DC中
if (nWidthDest == nWidthSrc && nHeightDest == nHeightSrc)
BitBlt(hImageDC, 0, 0, nWidthDest, nHeightDest, hdcSrc, nXOriginSrc, nYOriginSrc, SRCCOPY);
else
StretchBlt(hImageDC, 0, 0, nWidthDest, nHeightDest,
hdcSrc, nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc, SRCCOPY);
// 设置透明色
SetBkColor(hImageDC, crTransparent); // 生成透明区域为白色,其它区域为黑色的掩码位图
BitBlt(hMaskDC, 0, 0, nWidthDest, nHeightDest, hImageDC, 0, 0, SRCCOPY);
// 生成透明区域为黑色,其它区域保持不变的位图
SetBkColor(hImageDC, RGB(0,0,0));
SetTextColor(hImageDC, RGB(255,255,255));
BitBlt(hImageDC, 0, 0, nWidthDest, nHeightDest, hMaskDC, 0, 0, SRCAND); // 透明部分保持屏幕不变,其它部分变成黑色
SetBkColor(hdcDest,RGB(0xff,0xff,0xff));
SetTextColor(hdcDest,RGB(0,0,0));
BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hMaskDC, 0, 0, SRCAND);
// "或"运算,生成最终效果
BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest, hImageDC, 0, 0, SRCPAINT);
SelectObject(hImageDC, hOldImageBMP);
DeleteDC(hImageDC);
SelectObject(hMaskDC, hOldMaskBMP);
DeleteDC(hMaskDC);
DeleteObject(hImageBMP);
DeleteObject(hMaskBMP);
}// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.void CTransparentBltTestDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{ SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
COLORREF crMask = RGB(0x00,0x00,0xff);
BITMAP bm;
m_bmpFootball.GetBitmap(&bm);
int nWidth = bm.bmWidth;
int nHeight = bm.bmHeight;
CDC ImageDC;
ImageDC.CreateCompatibleDC(&dc);
CBitmap *pOldImageBMP = ImageDC.SelectObject(&m_bmpFootball);
//::TransparentBlt(dc.m_hDC,50,40,nWidth,nHeight,ImageDC.m_hDC,0,0,nWidth,nHeight,crMask);
TransparentBlt2(dc.m_hDC,50,40,nWidth,nHeight,ImageDC.m_hDC,0,0,nWidth,nHeight,crMask);
ImageDC.SelectObject(pOldImageBMP);
}
}