文档章节

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
VC 6.0 配置和使用gdi+

GDI+ GDI+是Windows XP中的一个子系统,它主要负责在显示屏幕和打印设备输出有关信息,它是一组通过C++类实现的应用程序编程接口。顾名思义,GDI+是以前版本GDI的继承者,出于兼容性考虑,W...

junwong
2012/03/23
1K
0
Matplotlib 绘图使用指南

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

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

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

雷锋字幕组
05/22
0
0
GDI+图像处理学习笔记——改变图像的透明度

GDI+是WindowsXp和windows Server 2003中的一个子系统,主要用于处理系统的绘制消息。GDI+是GDI的扩展,其继承了GDI的有点并在其基础上进行了改进,包括增加了一些GDI无法绘制的图形函数,同...

晨曦之光
2012/05/23
491
0

没有更多内容

加载失败,请刷新页面

加载更多

OSChina 周日乱弹 —— 懒床是对冬天最起码的尊重

Osc乱弹歌单(2018)请戳(这里) 【今日歌曲】 @瘟神灬念 :分享daniwellP/桃音モモ的单曲《Nyan Cat》 《Nyan Cat》- daniwellP/桃音モモ 手机党少年们想听歌,请使劲儿戳(这里) @巴拉迪...

小小编辑
今天
41
2
码云项目100,水一发

简单回顾一下: 早期构想最多的,是希望能将PHP一些类和编码分区做得更细,所以很多尝试。但不得不说,PHP的功能过于单一,是的,也许写C/C++扩展,可以解决问题,那我为什么不用C#或者Golan...

曾建凯
今天
4
0
Spring应用学习——AOP

1. AOP 1. AOP:即面向切面编程,采用横向抽取机制,取代了传统的继承体系的重复代码问题,如下图所示,性能监控、日志记录等代码围绕业务逻辑代码,而这部分代码是一个高度重复的代码,也就...

江左煤郎
今天
4
0
eclipse的版本

Eclipse各版本代号一览表 Eclipse的设计思想是:一切皆插件。Eclipse核心很小,其它所有功能都以插件的形式附加于Eclipse核心之上。 Eclipse基本内核包括:图形API(SWT/Jface),Java开发环...

mdoo
今天
3
0
SpringBoot源码:启动过程分析(一)

本文主要分析 SpringBoot 的启动过程。 SpringBoot的版本为:2.1.0 release,最新版本。 一.时序图 还是老套路,先把分析过程的时序图摆出来:时序图-SpringBoot2.10启动分析 二.源码分析 首...

Jacktanger
今天
12
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部