GdiPlus[37]: IGPGraphicsPath (四) 路径变换 转

涂孟超

``````IGPGraphicsPath.Flatten();   //把路径中的曲线转换为近似直线段(路径中只有 Bezier 线和直线).
IGPGraphicsPath.Outline();   //同 Flatten();
IGPGraphicsPath.Warp();      //四边形或平行四边形扭曲.
IGPGraphicsPath.Widen();     //把轮廓转换为范围.
IGPGraphicsPath.Transform(); //矩阵变换; 其实上面几个方法都包含矩阵变换的参数.

``````

Flatten 测试图:

Flatten 测试代码:

``````uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Pen: IGPPen;
Brush: IGPBrush;
Path, PathClone: IGPGraphicsPath;
Rect: TGPRect;
Pt: TGPPoint;
Matrix: IGPMatrix;
begin
Graphics := TGPGraphics.Create(Canvas.Handle);
Pen := TGPPen.Create(\$FFFF0000);
Brush := TGPSolidBrush.Create(\$800000FF);
Path := TGPGraphicsPath.Create;
Rect.Initialize(20, 20, 200, 75);

PathClone := Path.Clone;
Graphics.DrawPath(Pen, PathClone);
for Pt in PathClone.PathPointsI do Graphics.FillRectangle(Brush, Pt.X-2, Pt.Y-2, 4, 4);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

PathClone := Path.Clone;
PathClone.Flatten(); //其参数 2 默认是 0.25
Graphics.DrawPath(Pen, PathClone);
for Pt in PathClone.PathPointsI do Graphics.FillRectangle(Brush, Pt.X-2, Pt.Y-2, 4, 4);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

PathClone := Path.Clone;
PathClone.Flatten(nil, 10);
Graphics.DrawPath(Pen, PathClone);
for Pt in PathClone.PathPointsI do Graphics.FillRectangle(Brush, Pt.X-2, Pt.Y-2, 4, 4);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

PathClone := Path.Clone;
PathClone.Flatten(nil, 25);
Graphics.DrawPath(Pen, PathClone);
for Pt in PathClone.PathPointsI do Graphics.FillRectangle(Brush, Pt.X-2, Pt.Y-2, 4, 4);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

PathClone := Path.Clone;
PathClone.Flatten(nil, 50);
Graphics.DrawPath(Pen, PathClone);
for Pt in PathClone.PathPointsI do Graphics.FillRectangle(Brush, Pt.X-2, Pt.Y-2, 4, 4);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);

PathClone := Path.Clone;
Matrix := TGPMatrix.Create;
Matrix.Scale(1, 0.5);
Matrix.Translate(0, 20);
PathClone.Flatten(Matrix, 25);
Graphics.DrawPath(Pen, PathClone);
for Pt in PathClone.PathPointsI do Graphics.FillRectangle(Brush, Pt.X-2, Pt.Y-2, 4, 4);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
end;

``````

Warp 测试图:

Warp 测试代码:

``````uses GdiPlus;

const
{ 数组有三个元素时, 0: 左上; 1: 右上; 2: 左下; 3: 自动调整为平行四边形 }
pts3: array[0..2] of TGPPointF = ((X:20; Y:20),(X:250; Y:0),(X:20; Y:120));

{ 数组有四个元素时, 0: 左上; 1: 右上; 2: 左下; 3: 右下 }
pts4: array[0..3] of TGPPointF = ((X:20; Y:20),(X:220; Y:10),(X:20; Y:120),(X:270; Y:190));

procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Brush: IGPHatchBrush;
Path,PathClone: IGPGraphicsPath;
Rect: TGPRectF;
FontFamily: IGPFontFamily;
StringFormat: IGPStringFormat;
Pt: TGPPointF;
begin
Graphics := TGPGraphics.Create(Canvas.Handle);
Brush := TGPHatchBrush.Create(HatchStyleShingle, \$FF808080, \$FF483D8B);

Rect.Initialize(20, 20, 250, 120);
FontFamily := TGPFontFamily.Create('Arial Black');
StringFormat := TGPStringFormat.Create;
StringFormat.Alignment := StringAlignmentCenter;
StringFormat.LineAlignment := StringAlignmentCenter;

Path := TGPGraphicsPath.Create;
Path.AddString('Delphi', FontFamily, [], 56, Rect, StringFormat);

PathClone := Path.Clone;
Graphics.FillPath(Brush, PathClone);
Graphics.TranslateTransform(0, Rect.Y*2 + Rect.Height);

//PathClone := Path.Clone;
PathClone.Warp(pts3, Rect);
Graphics.FillPath(Brush, PathClone);
Graphics.TranslateTransform(0, Rect.Y*2 + Rect.Height);

PathClone := Path.Clone;
PathClone.Warp(pts4, Rect);
Graphics.FillPath(Brush, PathClone);
Graphics.TranslateTransform(0, Rect.Y*2 + Rect.Height);
end;

``````

Widen 测试图:

Widen 测试代码:

``````uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Pen: IGPPen;
Brush: IGPHatchBrush;
Path, PathClone: IGPGraphicsPath;
Rect: TGPRect;
begin
Graphics := TGPGraphics.Create(Canvas.Handle);
Pen := TGPPen.Create(\$AAFF0000, 20);
Brush := TGPHatchBrush.Create(HatchStyleShingle, \$FFC0C0C0, \$FF888888);
Path := TGPGraphicsPath.Create;
Rect.Initialize(20, 20, 200, 75);

PathClone := Path.Clone;
Graphics.FillPath(Brush, PathClone);
Graphics.DrawPath(Pen, PathClone);
Graphics.TranslateTransform(0, Rect.Y*2 + Rect.Height);

PathClone := Path.Clone;
PathClone.Widen(Pen);
Graphics.FillPath(Brush, PathClone);
Pen.Width := 1;
Graphics.DrawPath(Pen, PathClone);
Graphics.TranslateTransform(0, Rect.Y + Rect.Height);
end;

``````

Translate 测试图:

Translate 测试代码:

``````uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
Graphics: IGPGraphics;
Brush: IGPHatchBrush;
Path,PathClone: IGPGraphicsPath;
FontFamily: IGPFontFamily;
Pt: TGPPointF;
Matrix: IGPMatrix;
begin
Graphics := TGPGraphics.Create(Canvas.Handle);
Brush := TGPHatchBrush.Create(HatchStyleZigZag, \$FFC0C0C0, \$FFFF0000);

FontFamily := TGPFontFamily.Create('Arial Black');
Pt.Initialize(0, 0);
Path := TGPGraphicsPath.Create;
Path.AddString('Delphi', FontFamily, [], 32, Pt, nil);

Graphics.FillPath(Brush, Path);

PathClone := Path.Clone;
Matrix := TGPMatrix.Create;
Matrix.Scale(2, 2);
Matrix.Rotate(-30);
Matrix.Translate(-35, 45);
PathClone.Transform(Matrix);
Graphics.FillPath(Brush, PathClone);

PathClone := Path.Clone;
Matrix.Reset;
Matrix.Scale(2.5, 6);
Matrix.Translate(0, 18);
PathClone.Transform(Matrix);
Graphics.FillPath(Brush, PathClone);
end;

``````

涂孟超

GDI+里面的问题。。。。。。。。。。

error C2248: “Gdiplus::Bitmap::Bitmap”: 无法访问 private 成员(在“Gdiplus::Bitmap”类中声明) 1> c:\program files\microsoft sdks\windows\v7.0a\include\gdiplusheaders.h(630) : ......

xxdd
2013/10/24
74
0
Wine 1.5.0 发布-兼容windows程序

Wine 1.5 是一个开发版本，和之前的wine 1.4 的区别就在于1.4是一个稳定版本，所以如果你不想做实验，就不要安装wine 1.5的开发版本了。 在此版本中有什么新的功能： 新版本的Gecko引擎。 部...

2012/03/17
1K
0
vs 2005 添加GDI配置

2015/12/08
133
0

hack_tian
2018/04/11
0
0
MFC边框重绘

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 pragma once incl......

2016/01/30
635
0

【0918】正则介绍_grep

【0918】正则介绍_grep 9.1 正则介绍_grep上 9.2 grep中 9.3 grep下 一、正则介绍 正则是一串有规律的字符串，它使用单个字符串来描述或匹配一系列符合某个语法规则的字符串。 二、grep工具 ...

31分钟前
4
0

1. 网页加载速度更快 在网站中使用CDN技术最直接的一个好处就是它可以加快网页的加载速度。首先，CDN加速的内容分发是基于服务器缓存的，由于CDN中缓存了不少数据，它能够给用户提供更快的页...

8
0

symbiochina88

4
0

SOM-TL437xF是一款广州创龙基于TI AM437x ARM Cortex-A9 + Xilinx Spartan-6 FPGA芯片设计的核心板，采用沉金无铅工艺的10层板设计，适用于高速数据采集和处理系统、汽车导航、工业自动化等领...

Tronlong创龙

5
0

好程序员Java学习路线分享MyBatis之线程优化，我们的项目存在大量用户同时访问的情况，那么就会出现大量线程并发访问数据库，这样会带来线程同步问题，本章我们将讨论MyBatis的线程同步问...

6
0