文档章节

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

涂孟超
 涂孟超
发布于 2014/09/26 15:36
字数 970
阅读 6
收藏 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博客
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
Word 2003绘图技巧

Word 中的图文混排功能非常强大,我们常用 Microsoft Word 来编制数学教案、试卷、打印文稿,但是绘图往往令人头疼.其实 Word 中的制图功能比较强大,有许多技巧.若在使用过程中细心体会反...

麻新鑫
2012/10/26
332
1
Matplotlib 绘图使用指南

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

7125messi
07/04
0
0

没有更多内容

加载失败,请刷新页面

加载更多

【解惑】领略Java内部类的“内部”

内部类有两种情况: (1) 在类中定义一个类(私有内部类,静态内部类) (2) 在方法中定义一个类(局部内部类,匿名内部类) 1、私有内部类 —— 在方法之间定义的内部类,非静态 我们首先看看类中...

偶尔诗文
16分钟前
0
0
sqlserver 2008 r2 直接下载地址(百度云)

之前下载的sqlserver2008发现不能附加,就卸载了,重新找到了sqlserver2008R2的百度云资源 卸载sqlserver2008还是有点麻烦,不过就是需要删除注册表中的信息 自己来回卸载了3次终于重装sqlse...

dillonxiao
46分钟前
1
0
[Java]JVM调优总结 -Xms -Xmx -Xmn -Xss

JVM调优总结 -Xms -Xmx -Xmn -Xss 博客分类: Java General JVM应用服务器电信CMS算法 堆大小设置 JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制;系统的可...

morpheusWB
56分钟前
2
0
C++ std::function 和 std::bind

C++11提供了std::function和std::bind两个工具,用于引用可调用对象。这些可调用对象包括 普通函数,Lambda表达式,类的静态成员函数,非静态成员函数以及仿函数等。引用可调用对象,可以用于...

yepanl
今天
4
0
python:可迭代对象的索引

关于 python的range的用法: 注意是[ 开始,结束)的半开区间,不包括结束 http://www.runoob.com/python/python-func-range.html import collectionsfrom collections import Iterable字符串......

Oh_really
今天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部