椭圆的透明边界框

Transparent bounding box of an ellipse

我正在编写一些 C++ 代码来绘制椭圆。有时,这些椭圆可以在一个分组中相互堆叠。当它们相互堆叠时,我希望椭圆的边界框是透明的,这样我就看不到边界框的白色角。见下图。

是否包含 SetBkMode 似乎没有什么区别。如果我不执行 FillRect,我会在边界框上看到黑色背景。


HBRUSH brush = CreateSolidBrush(RGB(255, 255, 255));
CDC *pDC = CDC::FromHandle(pSprite->hDCMem);
pDC->SetBkMode(TRANSPARENT);
pDC->FillRect(m_SpriteRect, CBrush::FromHandle(brush));
pDC->SelectObject(m_BackBrush);
pDC->Ellipse(m_SpriteRect);
pDC->SetBkMode(OPAQUE);

DeleteObject(brush);

有没有办法设置透明背景?

如果在内存dc上绘图,用透明色填充背景,然后使用TransparentBlt将内存dc blit到最终HDC。示例:

CDC *pDC = CDC::FromHandle(hDCMem);

//fill the background with transparent color
COLORREF clr_transparent = RGB(255, 255, 255); //<- randomly selected color
CBrush brush(clr_transparent);
pDC->FillRect(m_SpriteRect, &brush);

//any drawing
auto oldbrush = pDC->SelectObject(m_BackBrush);
pDC->Ellipse(m_SpriteRect);
pDC->SelectObject(oldbrush);

//transparent blit
TransparentBlt(final_hdc, x_dest, y_dest, width, height, 
    hDCMem, 0, 0, m_SpriteRect.right, m_SpriteRect.bottom, clr_transparent);