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

时间: 2024-08-05 18:57:37

GDI+绘制渐变色的相关文章

使用GDI绘制验证码

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace 使用GDI绘制验证码B { public parti

新手们的GDI+绘制方格

//绘制panel控件触发的事件 //不可在窗体加载时绘制方格        private void panel1_Paint(object sender, PaintEventArgs e)        {            int rowNum = 12;//行数            int colNum = 15;//列数:            Pen pen = new Pen(Color.Black);//实例化一个"画笔"            Brush br

D2D引擎与GDI\GDI+绘制效果对比

本例主要是对比D2D和GDI在绘制文字.线条的区别,以及D2D与GDI+在绘制图片时的区别. D2D是基于COM组件开发的,使用前的CoInitialize(NULL)是必须的:另外,GDI+的初始化GdiplusStartup()也别忘了. 废话少说,完整代码如下: // D2DDemo.cpp : 定义应用程序的入口点. // #include "stdafx.h" #include "D2DDemo.h" #include <D2D1.h> #in

通过GDI+绘制 验证码

只为了记录下自己的学习历程,方便日后查看 现在开始言归正传,以下为其完整代码附上 GDI+绘制验证码 以下为运行结果图

MFC 用gdi绘制填充多边形区域

MFC 用gdi绘制填充多边形区域 这里的代码是实现一个三角形的绘制,并用刷子填充颜色 在OnPaint()函数里面 运用的是给定的三角形的三个点,很多个点可以绘制多边形 [cpp] view plaincopy CBrush br(RGB(40,130,170)); CRgn rgn; CPoint arrpt[3]; arrpt[0].x = m_rcAT.right-8; arrpt[0].y = m_rcAT.top+m_rcAT.Height()*2/5; arrpt[1].x = a

C#利用GDI+绘制旋转文字等效果

C#中利用GDI+绘制旋转文本的文字,网上有很多资料,基本都使用矩阵旋转的方式实现.但基本都只提及按点旋转,若要实现在矩形范围内旋转文本,资料较少.经过琢磨,可以将矩形内旋转转化为按点旋转,不过需要经过不少的计算过程.利用下面的类可以实现该功能. [csharp] view plaincopy using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D;

C#利用GDI+绘制旋转文字等效果实例

本文实例讲述了C#利用GDI+绘制旋转文字等效果的方法,是非常实用的技巧.分享给大家供大家参考之用.具体如下: C#中利用GDI+绘制旋转文本的文字,网上有很多资料,基本都使用矩阵旋转的方式实现.但基本都只提及按点旋转,若要实现在矩形范围内旋转文本,资料较少.经过琢磨,可以将矩形内旋转转化为按点旋转,不过需要经过不少的计算过程.利用下面的类可以实现该功能. 具体实现代码如下: using System; using System.Collections.Generic; using System

C#GDI 绘制线段(实线或虚线)、矩形、字符串、圆、椭圆

C#GDI 绘制线段(实线或虚线).矩形.字符串.圆.椭圆 绘制基本线条和图形 比较简单,直接看代码. 1 Graphics graphics = e.Graphics; 2 3 //绘制实线 4 using (Pen pen = new Pen(Color.Black, 2)) 5 { 6 pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid; //实现 7 graphics.DrawLine(pen,0,10,100,10); 8

C# GDI绘制验证码

步骤: 1.通过Random生成随机数或字符及验证码 2.通过验证码内容长度生成指定大小的图片 3.获取生成图片的Graphics对象 4.定义验证码字体格式 5.通过指定字体将验证码绘制到图片 6.向图片上添加背景噪音线 7.添加前景噪音点 1 private void pictureBox1_Click(object sender, EventArgs e) 2 { 3 Random r = new Random(); 4 string str = null; 5 for (int i =