本套接口只有两个单元: 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.

posted on 2009-12-11 13:55  万一  阅读(3509)  评论(16编辑  收藏  举报