当前位置:网站首页>Use of path gradient brush in gdi+
Use of path gradient brush in gdi+
2022-06-09 12:44:00 【litanyuan】
background
A path is a series of interconnected lines and curves , Consisting of many different types of points , Used to represent complex irregular figures , GraphicsPath Class represents .
Path gradient brush allows you to set a brush with a color gradient from the center to the boundary , You can set the color of the center point and the color of the boundary point .
Build path gradient brush
①. Use the path to build
void DemoGDI::DrawUser(HDC hdc)
{
Graphics graphics(hdc);// structure Graphics object
Pen m_pen(Color::Blue,2);
SolidBrush m_Brush(Color::Green);
GraphicsPath m_Path;// Construct an empty path
m_Path.AddEllipse(30, 30, 180, 120);// Add ellipses
PathGradientBrush pathBrush(&m_Path);// Create brushes using paths
pathBrush.SetCenterColor(Color::Red);// Set center color
Color colors[] = {
Color::Green ,Color::Green};
int count = 1;
pathBrush.SetSurroundColors(colors, &count);// Set the border color
graphics.FillEllipse(&pathBrush, 30, 30, 180, 120);
}

②. Use points to build
void DemoGDI::DrawUser(HDC hdc)
{
Graphics graphics(hdc);// structure Graphics object
Pen m_pen(Color::Blue,2);
SolidBrush m_Brush(Color::Green);
Point points[] = {
Point(30, 30), Point(180, 30), Point(180, 150), Point(30, 150) };
PathGradientBrush pathBrush(points,4);// Use points to create brushes
pathBrush.SetCenterColor(Color::Red);// Set center color
Color colors[] = {
Color::Green ,Color::Black,Color::Yellow,Color::Blue};
int count = 4;
pathBrush.SetSurroundColors(colors, &count);// Set the border color
graphics.FillRectangle(&pathBrush, 30, 30, 150, 120);
}

Focus and zoom
①. summary
Focus zoom is used to specify the internal track inside the master track , The center color fills the entire internal track range , Not just at the center point . You can call SetFocusScales Method to set Focus and zoom of a path gradient brush .
②. Set focus zoom
void DemoGDI::DrawUser(HDC hdc)
{
Graphics graphics(hdc);// structure Graphics object
Pen m_pen(Color::Blue, 2);
SolidBrush m_Brush(Color::Green);
GraphicsPath m_Path;// Construct an empty path
m_Path.AddEllipse(30, 30, 180, 120);// Add ellipses
PathGradientBrush pathBrush(&m_Path);// Create brushes using paths
pathBrush.SetCenterColor(Color::Red);// Set center color
Color colors[] = {
Color::Green ,Color::Green };
int count = 1;
pathBrush.SetSurroundColors(colors, &count);// Set the border color
pathBrush.SetFocusScales(0.3f, 0.3f);// Set focus zoom
graphics.FillEllipse(&pathBrush, 30, 30, 180, 120);
}

Interpolation color
①. summary
Using the interpolation color array, you can realize the gradient of multiple colors from the path boundary to the center point .
②. Use interpolated color gradients
void DemoGDI::DrawUser(HDC hdc)
{
Graphics graphics(hdc);// structure Graphics object
Pen m_pen(Color::Blue, 2);
SolidBrush m_Brush(Color::Green);
GraphicsPath m_Path;// Construct an empty path
m_Path.AddRectangle(Rect(30,30,180,120));// Add rectangle
PathGradientBrush pathBrush(&m_Path);// Create brushes using paths
Color colors[] = {
Color(255, 0, 128, 0),Color(255, 0, 255, 255),Color(255, 0, 0, 255) };
REAL positions[] = {
0.0f, 0.5f, 1.0f };
pathBrush.SetInterpolationColors(colors, positions, 3);
graphics.FillRectangle(&pathBrush, 30, 30, 180, 120);
}

Other parameter settings
①. Center point setting
void DemoGDI::DrawUser(HDC hdc)
{
Graphics graphics(hdc);// structure Graphics object
Pen m_pen(Color::Blue, 2);
SolidBrush m_Brush(Color::Green);
GraphicsPath m_Path;// Construct an empty path
m_Path.AddEllipse(30, 30, 180, 120);// Add ellipses
PathGradientBrush pathBrush(&m_Path);// Create brushes using paths
pathBrush.SetCenterColor(Color::Red);// Set center color
Color colors[] = {
Color::Green ,Color::Green };
int count = 1;
pathBrush.SetSurroundColors(colors, &count);// Set the border color
pathBrush.SetCenterPoint(Point(150, 75));
graphics.FillEllipse(&pathBrush, 30, 30, 180, 120);
}

②. Use grayscale correction
void DemoGDI::DrawUser(HDC hdc)
{
Graphics graphics(hdc);// structure Graphics object
Pen m_pen(Color::Blue, 2);
SolidBrush m_Brush(Color::Green);
GraphicsPath m_Path;// Construct an empty path
m_Path.AddEllipse(30, 30, 180, 120);// Add ellipses
PathGradientBrush pathBrush(&m_Path);// Create brushes using paths
pathBrush.SetCenterColor(Color::Red);// Set center color
Color colors[] = {
Color::Green ,Color::Green };
int count = 1;
pathBrush.SetSurroundColors(colors, &count);// Set the border color
pathBrush.SetGammaCorrection(true);// Use grayscale correction
graphics.FillEllipse(&pathBrush, 30, 30, 180, 120);
}

边栏推荐
- 实验室常用工具 | 实验溶液配制 | 摩尔浓度及分子量计算工具 molarity-calculator
- LR11 installation error: vc2005 is missing on this computer_ sp1_ with_ atl_ fix_ Redist, please install all missing required components, and then run this installation again.
- Redis数据结构与介绍
- Go language time Format pit
- Zabbix6.0新功能Geomap 地图标记 你会用吗?
- ThreadPoolExecutor 从精通到入门
- Google chrome插件 | pagenote 网页标记
- Xiemengjun: China's go language leader in the fifth year of entrepreneurship
- Tag greedy - brush questions to prepare knowledge - greedy problem solving methods + lt.455 Distribute cookies + lt.376 Wobble sequence
- PMP project management knowledge system
猜你喜欢

Google chrome插件 | pagenote 网页标记
![[译]PostgreSQL 怎么通过vacuum 加速事务ID回收的速度](/img/15/396fe394af73b19a9ff0dd984c6682.png)
[译]PostgreSQL 怎么通过vacuum 加速事务ID回收的速度

Range method returns the object conversion method

Common laboratory tools | preparation of experimental solution | molarity calculator

. Net basic knowledge quick pass 11

Safari的Favorites项不显示在主页上

kolla-ansible openstack登录 证书不可用

Origin 2022b | 更新及安装 | 中英文切换

Origin 2022b | update and installation | switch between Chinese and English

死锁的排查工具有哪些?
随机推荐
实验室常用工具 | 实验溶液配制 | 摩尔浓度及分子量计算工具 molarity-calculator
Scientific research paper writing
Flutter插件推荐spider
PostgreSQL每周新闻—2022年6月1日
Redission 使用
匿名内部类与局部变量
GaussDB(for Redis)新特性发布:前缀搜索千倍提升与集群版多租隔离
5. < tag backtracking and cutting problems > lt.93 Restore IP address
Software project management
Please talk about optimistic lock, pessimistic lock and applicable scenarios
GDI+ 中区域的使用
你不得不懂的mysql隔离级别底层
[reprint] understand G1 garbage collector
Inventory of existing open source software license compliance tools
What are the deadlock troubleshooting tools?
kolla-ansible openstack登录 证书不可用
Redis数据结构与介绍
9. lt.491 Longest increasing subsequence
UDP reliability practices
Classes internes anonymes et variables locales