再学 GDI+[72]: 区域(1) - 建立区域
2008-06-29 21:48
344 查看
建立 GDI+ 的区域有五种办法:
1、根据一个矩形建立(矩形区域);
2、根据路径建立;
3、根据 GDI 区域的句柄建立;
4、根据从区域中获取的数据建立;
5、无参数建立.
本例演示了前三种建立方法.
本例效果图:
代码文件:
窗体文件:
1、根据一个矩形建立(矩形区域);
2、根据路径建立;
3、根据 GDI 区域的句柄建立;
4、根据从区域中获取的数据建立;
5、无参数建立.
本例演示了前三种建立方法.
本例效果图:
代码文件:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) RadioGroup1: TRadioGroup; procedure FormCreate(Sender: TObject); procedure FormPaint(Sender: TObject); procedure RadioGroup1Click(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} uses GDIPOBJ, GDIPAPI; procedure TForm1.FormCreate(Sender: TObject); begin RadioGroup1.Items.CommaText := '矩形通道,椭圆形通道,多边形通道'; RadioGroup1.ItemIndex := 0; end; procedure TForm1.FormPaint(Sender: TObject); var rt: TGPRect; pts: array[0..2] of TPoint; RgnHandle: HRGN; g: TGPGraphics; path: TGPGraphicsPath; b: TGPBrush; rgn: TGPRegion; begin rt := MakeRect(20, 20, 100, ClientHeight-40); pts[0] := Point(rt.X + rt.Width div 2, rt.Y); pts[1] := Point(rt.X, rt.Y + rt.Height); pts[2] := Point(rt.X + rt.Width, rt.Y + rt.Height); case RadioGroup1.ItemIndex of 0: rgn := TGPRegion.Create(rt); {根据矩形建立(矩形区域)} 1: begin {根据路径建立} path := TGPGraphicsPath.Create; path.AddEllipse(rt); rgn := TGPRegion.Create(path); path.Free; end; 2: begin {根据 GDI 区域的句柄建立} RgnHandle := CreatePolygonRgn(pts, Length(pts), WINDING); rgn := TGPRegion.Create(RgnHandle); DeleteObject(RgnHandle); end; end; g := TGPGraphics.Create(Canvas.Handle); b := TGPHatchBrush.Create(HatchStyleDiagonalCross, aclSilver, aclGray); g.FillRegion(b, rgn); b.Free; rgn.Free; g.Free; end; procedure TForm1.RadioGroup1Click(Sender: TObject); begin Repaint; end; end.
窗体文件:
object Form1: TForm1 Left = 0 Top = 0 Caption = 'Form1' ClientHeight = 137 ClientWidth = 238 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False Position = poDesktopCenter OnCreate = FormCreate OnPaint = FormPaint PixelsPerInch = 96 TextHeight = 13 object RadioGroup1: TRadioGroup Left = 137 Top = 8 Width = 91 Height = 121 Caption = 'RadioGroup1' TabOrder = 0 OnClick = RadioGroup1Click end end
相关文章推荐
- {Reship}{C#}{GDI+}GDI+画笔,线,区域类型
- WinAPI: CreateEllipticRgn、CreateEllipticRgnIndirect - 建立椭圆区域
- GDI+ 学习记录(6): 使用画刷建立画笔
- 虚拟内存空间的映射和虚拟区域的建立
- GDI+ 学习记录(29) 区域 - Region
- GDI+学习及代码总结之------画线、区域填充、写字
- 建立主DNS区域和辅助DNS区域的最佳实践
- 再学 GDI+[80]: 区域(9) - GetHRGN - 转为 GDI 的区域句柄
- WinAPI: CreateRoundRectRgn - 建立圆角矩形区域
- 如何用openCV将一副图像的部分区域截取重新建立图像啊????
- GDI+中区域的定义和绘制
- GDI+:自定义控件时如何使用Region来输出特定区域
- WinAPI: CreatePolygonRgn - 建立多边形区域
- GDI+ 学习记录(6) 使用画刷建立画笔
- 再学 GDI+[75]: 区域(4) - 根据区域剪切画板
- 粒子滤波器之建立选定区域直方图(histo_bin())
- gdi+ 局部刷新(区域的失效)
- WinAPI: CreatePolyPolygonRgn - 建立多个多边形构成的区域
- GDI+学习之------ 画线、区域填充、写字
- 简单的网线制作和小型区域网建立