How to fill a rectangle region with Semi-transparent brush in MFC?

故事扮演 提交于 2019-12-25 12:11:52

问题


I need to fill a rectangular region with semi-transparent color/brush in mfc. How can I achieve that?


回答1:


You can't just fill a rectangle with a semi-transparent brush, you'll need to use something like AlphaBlend or TransparentBlt to create the effect.

An example is available here:

http://www.codeproject.com/Articles/286/Using-the-AlphaBlend-function




回答2:


I found the solution. To fill the rectangle region with semi-transparent brush, we need to use GdiPlus objects.

Here is the Sample Code:

void FillSemiTransparentRegion(CDC *pDC, CRect rc)
{
    if (pDC == NULL || rc.IsRectEmpty() || rc.IsRectNull())
        return;

    Graphics gr(pDC->GetSafeHdc());

    SolidBrush br(Color(100, 0, 0, 0));    // Alpha, Red, Blue, Green

    gr.FillRectangle(&br, rc.left, rc.right, rc.Width(), rc.Height());
}


来源:https://stackoverflow.com/questions/22479272/how-to-fill-a-rectangle-region-with-semi-transparent-brush-in-mfc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!