文档章节

GdiPlus[33]: 基本绘图与填充命令

涂孟超
 涂孟超
发布于 2014/09/26 15:36
字数 970
阅读 9
收藏 0

DrawLine();
DrawLines();
DrawArc();
DrawBezier();
DrawBeziers();
DrawRectangle();
DrawRectangles();
DrawEllipse();
DrawPie();
DrawPolygon();
DrawCurve();
DrawClosedCurve();

FillRectangle();
FillRectangles();
FillPolygon();
FillEllipse();
FillPie();
FillClosedCurve();

 
 
 
 
 

 

 

  

DrawLines、DrawPolygon、FillPolygon 测试图:



DrawLines、DrawPolygon、FillPolygon 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
const
  Pts: array[0..3] of TGPPointF = ((X:20; Y:80), (X:60; Y:20), (X:100; Y:80), (X:60; Y:140));
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Brush: IGPSolidBrush;
  Font: IGPFont;
  i: Integer;
begin
  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  Brush := TGPSolidBrush.Create($FF000000);
  Font := TGPFont.Create(Canvas.Handle);

  Graphics.DrawLines(Pen, Pts);
  for i := 0 to Length(Pts) - 1 do Graphics.DrawString(IntToStr(i), Font, Pts[i], Brush);

  Graphics.TranslateTransform(110, 0);
  Graphics.DrawPolygon(Pen, Pts);

  Brush.Color := $FFFFFF00;
  Graphics.TranslateTransform(110, 0);
  Graphics.FillPolygon(Brush, Pts);

  Graphics.TranslateTransform(110, 0);
  Graphics.FillPolygon(Brush, Pts);
  Graphics.DrawPolygon(Pen, Pts);
end;

 
 
 
 
 

 

 

  

DrawRectangles、FillRectangles 测试图:



DrawRectangles、FillRectangles 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Brush: IGPSolidBrush;
  Rects: array[0..2] of TGPRect;
begin
  Rects[0].Initialize(40, 20, 20, 20);
  Rects[1].Initialize(30, 40, 40, 40);
  Rects[2].Initialize(10, 80, 80, 80);

  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  Brush := TGPSolidBrush.Create($FFC0C0C0);

  Graphics.DrawRectangles(Pen, Rects);

  Graphics.TranslateTransform(110, 0);
  Graphics.FillRectangles(Brush, Rects);

  Graphics.TranslateTransform(110, 0);
  Graphics.FillRectangles(Brush, Rects);
  Graphics.DrawRectangles(Pen, Rects);
end;

 
 
 
 
 

 

 

  

DrawArc、DrawPie、FillPie 测试图:



DrawArc、DrawPie、FillPie 测试代码:

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Brush: IGPSolidBrush;
  Rect: TGPRect;
begin
  Rect.Initialize(15, 15, 160, 80);

  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  Brush := TGPSolidBrush.Create($FFB0C4DE);

  Graphics.FillEllipse(Brush, Rect);
  Graphics.DrawArc(Pen, Rect, 0, 45);
  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

  Graphics.FillEllipse(Brush, Rect);
  Graphics.DrawPie(Pen, Rect, 0, 45);
  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

  Graphics.FillEllipse(Brush, Rect);
  Brush.Color := $FFFFD700;
  Graphics.FillPie(Brush, Rect, 0, 45);
  Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

  Brush.Color := $FFB0C4DE;
  Graphics.FillEllipse(Brush, Rect);
  Brush.Color := $FFFFD700;
  Graphics.FillPie(Brush, Rect, 0, 45);
  Graphics.DrawPie(Pen, Rect, 0, 45);
end;

 
 
 
 
 

 

 

  

DrawCurve、DrawClosedCurve、FillClosedCurve 测试图:



DrawCurve、DrawClosedCurve、FillClosedCurve 测试代码:

uses GdiPlus;

const
  Pts: array [0..5] of TGPPoint = (
    (X: 10;  Y:  40),
    (X: 100; Y:  60),
    (X: 150; Y:  20),
    (X: 130; Y: 100),
    (X: 70;  Y:  80),
    (X: 30;  Y: 140));

procedure TForm1.FormPaint(Sender: TObject);
const
  m = 180;
  n = 160;
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  BrushBak, Brush: IGPBrush;
begin
  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  BrushBak := TGPSolidBrush.Create($FFD8BFD8);
  Brush := TGPSolidBrush.Create($FFFFD700);

  with Graphics do
  begin
    FillPolygon(BrushBak, Pts);
    DrawCurve(Pen, Pts);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    DrawCurve(Pen, Pts, 1.5);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    DrawCurve(Pen, Pts, 0.5);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    DrawCurve(Pen, Pts, 0);

    //
    TranslateTransform(-Transform.OffsetX, 150);

    FillPolygon(BrushBak, Pts);
    DrawClosedCurve(Pen, Pts);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    DrawClosedCurve(Pen, Pts, 1.5);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    DrawClosedCurve(Pen, Pts, 0.5);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    DrawClosedCurve(Pen, Pts, 0);

    //
    TranslateTransform(-Transform.OffsetX, n);

    FillPolygon(BrushBak, Pts);
    FillClosedCurve(Brush, Pts);
    DrawClosedCurve(Pen, Pts);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    FillClosedCurve(Brush, Pts, FillModeAlternate, 1.5);
    DrawClosedCurve(Pen, Pts, 1.5);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    FillClosedCurve(Brush, Pts, FillModeAlternate, 0.5);
    DrawClosedCurve(Pen, Pts, 0.5);
    TranslateTransform(m, 0);

    FillPolygon(BrushBak, Pts);
    FillClosedCurve(Brush, Pts, FillModeAlternate, 0);
    DrawClosedCurve(Pen, Pts, 0);
  end;
end;

 
 
 
 
 

 

 

  

DrawBezier 测试图:



DrawBezier 测试代码:

uses GdiPlus;

//一条 Bezier 线需要四个点: 两个端点、两个控制点
procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  P1,C1,C2,P2: TGPPoint;
begin
  P1.Initialize(30, 100);
  C1.Initialize(120, 10);
  C2.Initialize(170, 150);
  P2.Initialize(220, 80);

  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FF0000FF, 2);

  Graphics.DrawBezier(Pen, P1, C1, C2, P2);

  Pen.Width := 1;
  Pen.Color := $FFFF0000;
  Graphics.DrawRectangle(Pen, P1.X-3, P1.Y-3, 6, 6);
  Graphics.DrawRectangle(Pen, P2.X-3, P2.Y-3, 6, 6);
  Graphics.DrawEllipse(Pen, C1.X-3, C1.Y-3, 6, 6);
  Graphics.DrawEllipse(Pen, C2.X-3, C2.Y-3, 6, 6);

  Pen.Color := $FFC0C0C0;
  Graphics.DrawLine(Pen, P1, C1);
  Graphics.DrawLine(Pen, P2, C2);
end;

//把一条当作多条画(DrawBeziers), 结果同上
procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Pts: array[0..3] of TGPPoint;
begin
  Pts[0].Initialize(30, 100);
  Pts[1].Initialize(120, 10);
  Pts[2].Initialize(170, 150);
  Pts[3].Initialize(220, 80);

  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FF0000FF, 2);

  Graphics.DrawBeziers(Pen, Pts);

  Pen.Width := 1;
  Pen.Color := $FFFF0000;
  Graphics.DrawRectangle(Pen, Pts[0].X-3, Pts[0].Y-3, 6, 6);
  Graphics.DrawRectangle(Pen, Pts[3].X-3, Pts[3].Y-3, 6, 6);
  Graphics.DrawEllipse(Pen, Pts[1].X-3, Pts[1].Y-3, 6, 6);
  Graphics.DrawEllipse(Pen, Pts[2].X-3, Pts[2].Y-3, 6, 6);

  Pen.Color := $FFC0C0C0;
  Graphics.DrawLine(Pen, Pts[0], Pts[1]);
  Graphics.DrawLine(Pen, Pts[3], Pts[2]);
end;

 
 
 
 
 

 

 

  

DrawBeziers 测试图:



DrawBeziers 测试代码:

uses GdiPlus;

const
  Pts: array[0..6] of TGPPoint = (
    (X: 24; Y: 32), // Pt1
    (X: 16; Y: 88), // C1
    (X: 36; Y:132), // C2
    (X:120; Y: 20), // Pt2
    (X:180; Y:150), // C3
    (X:210; Y: 90), // C4
    (X:210; Y: 20)  // Pt3
  );

//两条 Bezier 线需要 7 个点, 而不是 8 个; 因为 Bezier1 的终点即是 Bezier2 的起点;
//多条 Bezier 线需要的点数 = 3 * 线数 + 1;
//数组 ID 能被 3 整除的点是端点, 其他是控制点
procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Pen: IGPPen;
  Brush: IGPBrush;
  Rect: TGPRect;
  i: Integer;
begin
  Graphics := TGPGraphics.Create(Handle);
  Pen := TGPPen.Create($FFFF0000, 2);
  Brush := TGPSolidBrush.Create($800000FF);

  Graphics.DrawBeziers(Pen, Pts);

  for i := 0 to Length(Pts) - 1 do
  begin
    Rect.Initialize(Pts[i].X - 4, Pts[i].Y - 4, 8, 8);
    if i mod 3 = 0 then
      Graphics.FillRectangle(Brush, Rect)
    else
      Graphics.FillEllipse(Brush, Rect);
  end;
end;

 
 
 
 
 

 

 

  

本文转载自:http://www.cnblogs.com/del/archive/2009/12/16/1625966.html

共有 人打赏支持
涂孟超
粉丝 12
博文 2011
码字总数 14107
作品 0
深圳
程序员
私信 提问
Matplotlib 中文用户指南 8.1 屏幕截图

屏幕截图 原文:Screenshots 译者:飞龙 协议:CC BY-NC-SA 4.0 这里你会找到一些示例图和生成它们的代码。 简单绘图 这里是一个带有文本标签的基本的绘图: 源代码 子图示例 多个轴域(例如...

apachecn_飞龙
2017/01/30
0
0
python中的turtle库绘制图形

1. 前奏: 在用turtle绘制图形时,需要安装对应python的解释器以及IDE,我安装的是pycharm,在安装完pycharm后,在pycharm安装相应库的模块,绘图可以引入turtle模块,想要进行运算可以引入n...

---dgw博客
2018/04/07
0
0
iOS——Quartz2D(二维图形绘制)

1、Quartz2D 基本概述 Core Graphics Framework是一套基于C的API框架,使用了Quartz作为绘图引擎。它提供了低级别、轻量级、高保真度的2D渲染。 Quartz 2D是一个二维图形绘制引擎,适用于iOS...

kinglin_fu
2016/01/25
196
0
Matplotlib 绘图使用指南

大多数人不会花大量时间去学 matplotlib 库,仍然可以实现绘图需求,因为已经有人在 stackoverflow、github 等开源平台上提供了绝大多数画图问题的解决方案。我们通常会使用 google 来完成绘...

7125messi
2018/07/04
0
0
Python Matplotlib 绘图使用指南 (附代码)

雷锋网按:本文为雷锋字幕组编译的技术博客,原标题 Matplotlib Plotting Guide, 作者为 Prince Grover。 翻译 | 李振 于志鹏 整理 | 凡江 大多数人不会花大量时间去学 matplotlib 库,仍然...

雷锋字幕组
2018/05/22
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Coding and Paper Letter(四十五)

资源整理。 1 Coding: 1.Python库gempy,一种基于Python的开源三维结构地质建模软件,它允许从界面和方向数据隐式(即自动)创建复杂的地质模型。 它还支持随机建模以解决参数和模型的不确定...

胖胖雕
24分钟前
0
0
golang 声明一个指定长度的数组,用于后续添加

很多时候我们需要声明一个指定长度的数组,用于后续添加.在使用go的时候要注意,下面的第一个例子会有报错 "non-constant array bound",应该使用第二个例子. Length 是动态的值 有报错的例子 ...

漫步海边小路
27分钟前
0
0
Java NIO示例

Server端 /** * 《构建高性能的大型分布式Java应用》 * 书中的示例代码 * 版权所有 2008---2009 */package book.chapter1.tcpnio;import java.net.InetSocketAddress;i...

月下狼
33分钟前
0
0
发布xxl-job executor dotnet core 执行器的实现

DotXxlJob [github][https://github.com/xuanye/DotXxlJob] xxl-job的dotnet core 执行器实现,支持XXL-JOB 2.0+ 1 XXL-JOB概述 [XXL-JOB][1]是一个轻量级分布式任务调度平台,其核心设计目标...

假正经哥哥
今天
5
0
mysql 查询当天、本周,本月,上一个月的数据

今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM 表名 WHERE TO_DAYS( NOW( ) ) - TO_DAYS( 时间字段名) <= 1 近7天 SELECT * FROM 表名 wher......

BraveLN
今天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部