GDI+绘制渐变色

 

例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);
}

 

例2:

Graphics graphics(dc.GetSafeHdc());
graphics.Clear(Color::White);

//定义三种参与渐变的色彩
Color colors[] =
{
Color::Red, // 红色
Color::Green,//过渡色为绿色
Color::Blue // 蓝色
};

float positions[] =
{
0.0f, // 由红色起
0.3f, // 绿色始于画刷长度的三分之一
1.0f // 到蓝色止
};

//构造一条从黑色到白色的渐变画刷
LinearGradientBrush linGrBrush(
Point(0, 0),
Point(180, 0),
Color::Black,Color::White);

//设置渐变画刷的多色渐变信息
//linGrBrush.InterpolationColors=clrBlend;
linGrBrush.SetInterpolationColors(colors, positions, 3);
//使用多色渐变画刷填充目标区域
graphics.FillRectangle(&linGrBrush, 0, 0, 180, 100);

//使用普通的方法实现多色渐变
//由红到绿,长度60
LinearGradientBrush linGrBrush1(
Point(0, 0),
Point(60, 0),
Color::Red,
Color::Green);

//由绿到蓝,长度120
LinearGradientBrush linGrBrush2(
Point(60, 0),
Point(181, 0),
Color::Green,
Color::Blue);

//分别使用两个画刷填充两个相邻区域,形成多色渐变
graphics.FillRectangle(&linGrBrush1, 0, 120, 60, 100);
graphics.FillRectangle(&linGrBrush2, 60, 120, 120, 100);





原文地址:https://www.cnblogs.com/huhu0013/p/4625776.html