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





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值