位图透明色的裁剪

	COLORREF crl;
	GetWindowRect(&m_rtWnd);
	CRgn wndRgn, rgnTemp;

	CDC* pDC = GetWindowDC();
	CDC dcCompatible;

	dcCompatible.CreateCompatibleDC(pDC);
	CBitmap* pOldBitmap = dcCompatible.SelectObject(&m_bitmap);
	
	wndRgn.CreateRectRgn(0,0,m_rtWnd.Width(),m_rtWnd.Height());
	for(int x=0; x<m_rtWnd.Width(); x++)
	{
		for(int y=0; y<m_rtWnd.Height(); y++)
		{
			crl = dcCompatible.GetPixel(x, y);
			if(crl == TRANSCOLOR)
			{
				rgnTemp.CreateRectRgn(x, y, x+1, y+1);				
				wndRgn.CombineRgn(&wndRgn,&rgnTemp, RGN_XOR);//裁减掉透明色区域
				rgnTemp.DeleteObject();
			}
		}
	}

	//设置最终的窗口范围
	SetWindowRgn((HRGN)wndRgn,TRUE);
	
	dcCompatible.SelectObject(pOldBitmap);

	ReleaseDC(pDC);
	ReleaseDC(&dcCompatible);

转载于:https://www.cnblogs.com/rogee/archive/2011/04/02/2003314.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页