Gradient Brush in Native C++?

梦想的初衷 提交于 2020-01-04 17:32:11

问题


In c#, you can use drawing2d.lineargradientbrush, but in c++ right now I only found the CreateSolidBrush function. Is there a function in the native gdi dll to create a gradient brush? I couldn't find anything like this at msdn. Thanks


回答1:


To draw a vertical gradient:

void VerticalGradient(HDC hDC, const RECT& GradientFill, 
                      COLORREF rgbTop, COLORREF rgbBottom)
{
    GRADIENT_RECT gradientRect = { 0, 1 };
    TRIVERTEX triVertext[ 2 ] = {
        GradientFill.left - 1,
        GradientFill.top - 1,
        GetRValue(rgbTop) << 8,
        GetGValue(rgbTop) << 8,
        GetBValue(rgbTop) << 8,
        0x0000,         
        GradientFill.right,
        GradientFill.bottom,
        GetRValue(rgbBottom) << 8,
        GetGValue(rgbBottom) << 8,
        GetBValue(rgbBottom) << 8,
        0x0000
    };
    GradientFill(hDC, triVertext, 2, &gradientRect, 1, GRADIENT_FILL_RECT_V);
}



回答2:


You would have to use a combination of the Win32 API GradientFill, CreateCompatibleBitmap, and CreatePatternBrush




回答3:


C# uses GDI+ for Drawing2d. You can use GDI+ in C++ also - MSDN Creating a Linear Gradient



来源:https://stackoverflow.com/questions/1418399/gradient-brush-in-native-c

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