当前位置: 首页 > news >正文

再学 GDI+[66]: 路径画刷(6) - SetInterpolationColors、GetRectangle

本例效果图:

o_86283.png

代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormPaint(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses GDIPOBJ, GDIPAPI;

procedure TForm1.FormPaint(Sender: TObject);
var
  g : TGPGraphics;
  path: TGPGraphicsPath;
  pb: TGPPathGradientBrush;
  rt: TGPRect;
const
  pts: array[0..2] of TGPPoint = ((X:90; Y:10), (X:10; Y:160), (X:160; Y:160));
  colors: array[0..2] of TGPColor = (aclGreen, aclAqua, aclBlue);
  pos: array[0..2] of Single = (0.0, 0.25, 1.0); {颜色位置需要 >=0、<=1, 是百分比}
begin
  {三角}
  g := TGPGraphics.Create(Canvas.Handle);
  path := TGPGraphicsPath.Create;
  path.AddPolygon(PGPPoint(@pts), Length(pts));
  pb:= TGPPathGradientBrush.Create(path);
  pb.SetInterpolationColors(@colors, @pos, Length(colors)); {SetInterpolationColors}
  g.FillPath(pb, path);

  {矩形}
  pb.GetRectangle(rt); {GetRectangle}
  path.Reset;
  path.AddRectangle(rt);
  pb.Free;
  pb:= TGPPathGradientBrush.Create(path);
  pb.SetInterpolationColors(@colors, @pos, Length(colors));
  g.TranslateTransform(160, 0);
  g.FillPath(pb, path);

  {椭圆}
  path.Reset;
  path.AddEllipse(rt);
  pb.Free;
  pb:= TGPPathGradientBrush.Create(path);
  pb.SetInterpolationColors(@colors, @pos, Length(colors));
  g.TranslateTransform(160, 0);
  g.FillPath(pb, path);

  pb.Free;
  path.Free;
  g.Free;
end;

end.
窗体文件:
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 164
  ClientWidth = 491
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  Position = poDesktopCenter
  OnPaint = FormPaint
  PixelsPerInch = 96
  TextHeight = 13
end

相关文章:

  • statspack的IO操作及Buffer Hit Rate
  • Java 网络编程(2):UDP 的使用
  • 中国32个省的日语读法
  • JavaScript定时器原理分析
  • 技术的成长曲线
  • JAVA面试题解惑系列(六)——字符串(String)杂谈
  • InfoQ播客:Tal Weiss谈JVM的可观测性、插桩、以及字节码操作
  • 路由器测试的类型和方法
  • 【笔记3】用pandas实现矩阵数据格式的推荐算法 (基于用户的协同)
  • ccna视频第四讲
  • springmvc获取参数
  • seo工具总结
  • 基础练习 数列排序
  • 当爱已成为过去
  • C语音键盘钩子和用法 模拟键盘
  • [译]前端离线指南(上)
  • 【面试系列】之二:关于js原型
  • Angular6错误 Service: No provider for Renderer2
  • chrome扩展demo1-小时钟
  • CoolViewPager:即刻刷新,自定义边缘效果颜色,双向自动循环,内置垂直切换效果,想要的都在这里...
  • Docker: 容器互访的三种方式
  • gitlab-ci配置详解(一)
  • IDEA常用插件整理
  • LeetCode541. Reverse String II -- 按步长反转字符串
  • PHP那些事儿
  • Python爬虫--- 1.3 BS4库的解析器
  • TCP拥塞控制
  • ucore操作系统实验笔记 - 重新理解中断
  • XML已死 ?
  • 数据库写操作弃用“SELECT ... FOR UPDATE”解决方案
  • ​520就是要宠粉,你的心头书我买单
  • (LeetCode C++)盛最多水的容器
  • (poj1.2.1)1970(筛选法模拟)
  • (二)丶RabbitMQ的六大核心
  • (二十一)devops持续集成开发——使用jenkins的Docker Pipeline插件完成docker项目的pipeline流水线发布
  • (附源码)流浪动物保护平台的设计与实现 毕业设计 161154
  • (蓝桥杯每日一题)love
  • (力扣)循环队列的实现与详解(C语言)
  • (论文阅读32/100)Flowing convnets for human pose estimation in videos
  • (转)shell调试方法
  • .net oracle 连接超时_Mysql连接数据库异常汇总【必收藏】
  • .NET WebClient 类下载部分文件会错误?可能是解压缩的锅
  • .NET 设计模式初探
  • .net6 webapi log4net完整配置使用流程
  • .NET高级面试指南专题十一【 设计模式介绍,为什么要用设计模式】
  • .NET开源的一个小而快并且功能强大的 Windows 动态桌面软件 - DreamScene2
  • @EnableWebMvc介绍和使用详细demo
  • [AutoSar NVM] 存储架构
  • [bzoj 3534][Sdoi2014] 重建
  • [C#]C#学习笔记-CIL和动态程序集
  • [C#基础知识系列]专题十七:深入理解动态类型
  • [C/C++] -- 二叉树
  • [C++] Windows中字符串函数的种类
  • [C++基础]-入门知识
  • [codeforces] 25E Test || hash