GDI + Draw Gradient colors

Source: Internet
Author: User

Example 1:

void Ctextdlg::onpaint ()
{
Graphics graphics (This->m_hwnd);

LinearGradientBrush Lingrbrush (
Point (0,0),
Point (200,0),
Color (255,255,0,0),
Color (255,0,0,255));

Graphics. FillRectangle (&lingrbrush, 0, 0, 200, 200);
}

Example 2:

Graphics Graphics (DC. GETSAFEHDC ());
Graphics. Clear (color::white);

//define three different colors to participate in the gradient
Color colors[] =
{
color::red,//Red
color::green,//transition color to green
color::blue//Blue
};

float positions[] =
{
0.0f,//from Red
0.3f,//green starts at One-third of brush length
1.0f//To Blue stop
};

//Construct a gradient brush from black to white
LinearGradientBrush Lingrbrush (
Point (0, 0),
Point (0),
color::black,color::white);

//Set multicolor gradient information for a gradient brush
//lingrbrush.interpolationcolors=clrblend;
lingrbrush.setinterpolationcolors (colors, positions, 3);
//Fill the target area with a multi-color gradient brush
Graphics. FillRectangle (&lingrbrush, 0, 0, N.);

//Using a common method for multicolor gradients
//From red to green, length
LinearGradientBrush LinGrBrush1 (
Point (0, 0),
Point (0),
color::red,
color::green);

From green to blue, length 120
LinearGradientBrush LinGrBrush2 (
Point (60, 0),
Point (181, 0),
Color::green,
Color::blue);

Fill two adjacent areas with two brushes to form a multi-color gradient
Graphics. FillRectangle (&LINGRBRUSH1, 0, 120, 60, 100);
Graphics. FillRectangle (&LINGRBRUSH2, 60, 120, 120, 100);





GDI + Draw Gradient colors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.