随笔 - 2146  文章 - 97 评论 - 11765 trackbacks - 253


问题来源: http://www.cnblogs.com/del/archive/2009/01/23/1017571.html#1437673

本来 wuheng66888 需要的是输出旋转的文本, 下面的例子只是转了一个矩形;
因为 GDI+ 的旋转理念是旋转画布, 所以都是一样的.

本例效果图:



代码文件:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    procedure FormPaint(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses GDIPOBJ, GDIPAPI;

procedure TForm1.FormPaint(Sender: TObject);
var
  g: TGPGraphics;
  p: TGPPen;
  rect: TGPRect;
  pt: TGPPointF;
  Matrix: TGPMatrix;
begin
  g := TGPGraphics.Create(Canvas.Handle);
  p := TGPPen.Create(MakeColor(255,255,0,0),0);

  rect := MakeRect(30,30,100,100);

  {譬如准备在上面矩形的中心点旋转}
  pt := MakePoint(rect.X + rect.Width / 2, rect.Y + rect.Height /2);

  Matrix := TGPMatrix.Create;
  Matrix.RotateAt(45, pt); {以指定的 pt 为中心, 转 45° 角}

  {先画个不旋转的}
  g.DrawRectangle(p, rect);

  {再画个旋转的}
  p.SetColor(aclBlue);
  g.SetTransform(Matrix);  {关键代码}
  g.DrawRectangle(p, rect);

  g.ResetTransform;        {关键代码, 不恢复后面就都旋转了}

  Matrix.Free;
  p.Free;
  g.Free;
end;

end.


posted on 2009-01-23 17:00 万一 阅读(...) 评论(...) 编辑 收藏