myamanda

博客园 首页 新随笔 联系 订阅 管理
在窗体中添加一个button和一个image,选择一幅大约100x100的bitmap。
unit drawunit;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;
type
  TForm1 = class(TForm)
    Image1: TImage;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    rotateimage:timage;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
const
  rotation = 2/3*pi;
var
  x,y : integer;
  newx,newy : integer;
  radius,a : real;
begin
  form1.WindowState:=wsMaximized;
  image1.Visible:=false;
  button1.Visible:=false;
  rotateimage:=timage.Create(self);
  rotateimage.parent:=self;
  rotateimage.Left:=0;
  rotateimage.Top:=0;
  rotateimage.width:=740;
  rotateimage.Height:=540;
  for x:=1 to image1.Picture.Width do
  begin
    for y:=1 to image1.Height do
    begin
      radius:=Sqrt(Sqr(X)+Sqr(Y));
      a:=Arctan(Y/X);
      newx:=round(Radius*Cos(A+Rotation)+300);
      newy:=round(Radius*Sin(A+Rotation)+300);
      rotateimage.Canvas.Pixels[newx,newy]:=image1.Canvas.Pixels[x,y];
    end;
  end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  rotateimage.free;
end;
end.
posted on 2009-08-10 13:20  myamanda  阅读(297)  评论(0)    收藏  举报