MFC 导入透明背景的图片后 依然有白色背景 怎么弄掉 15
2个回答
展开全部
带缩放的透明显示的函数,最后Tcol要填写背景颜色,比如白色就填RGB(255,255,255),类似于BitBlt();你自己研究一下吧。
TransparentBlt2(HDC hdc0, int nX0, int nY0, int nW0, int nH0, HDC hdc1, int nX1, int nY1, int nW1, int nH1, UINT Tcol)
{
HBITMAP hBMP=CreateCompatibleBitmap(hdc0,nW0,nH0);
HBITMAP mBMP=CreateBitmap(nW0,nH0,1,1,NULL);
HDC hDC =CreateCompatibleDC(hdc0);
HDC mDC =CreateCompatibleDC(hdc0);
HBITMAP oldBMP =(HBITMAP)SelectObject(hDC,hBMP);
HBITMAP oldmBMP =(HBITMAP)SelectObject(mDC,mBMP);
if (nW0==nW1 && nH0==nH1)
BitBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,SRCCOPY);
else
StretchBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,nW1,nH1,SRCCOPY);
SetBkColor(hDC,Tcol);
BitBlt(mDC,0,0,nW0,nH0,hDC,0,0,SRCCOPY);
SetBkColor(hDC,RGB(0,0,0));
SetTextColor(hDC,RGB(255,255,255));
BitBlt(hDC,0,0,nW0,nH0,mDC,0,0,SRCAND);
SetBkColor(hdc0,RGB(255,255,255));
SetTextColor(hdc0,RGB(0,0,0));
BitBlt(hdc0,nX0,nY0,nW0,nH0,mDC,0,0,SRCAND);
BitBlt(hdc0,nX0,nY0,nW0,nH0,hDC,0,0,SRCPAINT);
SelectObject(hDC,oldBMP);
DeleteDC(hDC);
SelectObject(mDC,oldmBMP);
DeleteDC(mDC);
DeleteObject(hBMP);
DeleteObject(mBMP);
}
TransparentBlt2(HDC hdc0, int nX0, int nY0, int nW0, int nH0, HDC hdc1, int nX1, int nY1, int nW1, int nH1, UINT Tcol)
{
HBITMAP hBMP=CreateCompatibleBitmap(hdc0,nW0,nH0);
HBITMAP mBMP=CreateBitmap(nW0,nH0,1,1,NULL);
HDC hDC =CreateCompatibleDC(hdc0);
HDC mDC =CreateCompatibleDC(hdc0);
HBITMAP oldBMP =(HBITMAP)SelectObject(hDC,hBMP);
HBITMAP oldmBMP =(HBITMAP)SelectObject(mDC,mBMP);
if (nW0==nW1 && nH0==nH1)
BitBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,SRCCOPY);
else
StretchBlt(hDC,0,0,nW0,nH0,hdc1,nX1,nY1,nW1,nH1,SRCCOPY);
SetBkColor(hDC,Tcol);
BitBlt(mDC,0,0,nW0,nH0,hDC,0,0,SRCCOPY);
SetBkColor(hDC,RGB(0,0,0));
SetTextColor(hDC,RGB(255,255,255));
BitBlt(hDC,0,0,nW0,nH0,mDC,0,0,SRCAND);
SetBkColor(hdc0,RGB(255,255,255));
SetTextColor(hdc0,RGB(0,0,0));
BitBlt(hdc0,nX0,nY0,nW0,nH0,mDC,0,0,SRCAND);
BitBlt(hdc0,nX0,nY0,nW0,nH0,hDC,0,0,SRCPAINT);
SelectObject(hDC,oldBMP);
DeleteDC(hDC);
SelectObject(mDC,oldmBMP);
DeleteDC(mDC);
DeleteObject(hBMP);
DeleteObject(mBMP);
}
展开全部
其实所谓透明就是把对应位置的背景图片“截”下来再“贴”到你的控件上,看下面的代码:CClientDC clDC(GetParent());CRect rect;CRect rect1;GetClientRect(rect);GetWindowRect(rect1);GetParent()->ScreenToClient(rect1);if (m_dcBk.m_hDC == NULL){ m_dcBk.CreateCompatibleDC(&clDC); m_bmpBk.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height()); m_pbmpOldBk = m_dcBk.SelectObject(&m_bmpBk); m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);} // ifpDC->BitBlt(0, 0, rect.Width(), rect.Height(), &m_dcBk, 0, 0, SRCCOPY);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询