本套接口只有兩個單元: GdiPlus, GdiPlusHelpers; 主要的是前者, GdiPlusHelpers 的作用是通過 Helper 技術給 VCL 體系中的 TCanvas、TGraphicControl、TCustomControl、TBitmap 類補充添加 ToGPGraphics 方法, 以方便獲取 IGPGraphics.
在很多時候我們並不需要它, 這時也不需要 uses GdiPlusHelpers.
不過這對有些對象會很方便, 譬如: uses GdiPlusHelpers 後, TPanel 也有了 ToGPGraphics 方法.
嘗試下面代碼前, 先在窗體上添加 TImage、TPaintBox、TPanel 對象各一個.
本例效果圖:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
Image1: TImage;
PaintBox1: TPaintBox;
procedure FormPaint(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses GdiPlus, GdiPlusHelpers;
procedure TForm1.FormPaint(Sender: TObject);
var
Pen: IGPPen;
begin
Pen := TGPPen.Create(TGPColor.Red);
Image1.ToGPGraphics.DrawLine(Pen, 0, 0, Image1.Width, Image1.Height);
Image1.ToGPGraphics.DrawLine(Pen, 0, Image1.Height, Image1.Width, 0);
Pen.Color := TGPColor.LimeGreen;
PaintBox1.ToGPGraphics.DrawLine(Pen, 0, 0, PaintBox1.Width, PaintBox1.Height);
PaintBox1.ToGPGraphics.DrawLine(Pen, 0, PaintBox1.Height, PaintBox1.Width, 0);
Pen.Color := TGPColor.Blue;
Panel1.ToGPGraphics.DrawLine(Pen, 0, 0, Panel1.ClIEntWidth, Panel1.Height);
Panel1.ToGPGraphics.DrawLine(Pen, 0, Panel1.Height, Panel1.ClIEntWidth, 0);
end;
end.