unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Timer1: TTimer;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Wmf:TMetaFile;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled:=not Timer1.Enabled;
if Timer1.Enabled then
Button1.Caption:='Stop'
else
Button1.Caption:='Start';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Wmf:=TMetaFile.Create;
Wmf.Enhanced:=True;
Randomize;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
WmfCanvas:TMetafileCanvas;
X,Y:integer;
begin
Wmfcanvas:=TMetaFileCanvas.CreateWithComment(wmf,0,'Try','It Is a test!');
try
WmfCanvas.Brush.Color:=clWhite;
WmfCanvas.FillRect(WmfCanvas.ClipRect);
for x:=1 to 20 do
for y:=1 to 20 do
begin
WmfCanvas.MoveTo(22*(x+Random(2)),22*(Y+Random(2)));
WmfCanvas.Lineto(47*Y,47*X);
end;
finally
WmfCanvas.Free;
end;
Image1.canvas.Draw(0,0,Wmf);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Wmf.SaveToFile(ExtractFilePath(Paramstr(0))+'test.emf');
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Wmf.LoadFromFile(ExtractFilePath(Paramstr(0))+'test.emf');
Image1.Canvas.Draw(0,0,Wmf);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
Image1.Align:=alClient;
Image1.Align:=alNone;
Image1.Picture.Bitmap.Width:=Image1.Width;
Image1.Picture.Bitmap.Height:=Image1.Height;
Image1.Canvas.StretchDraw(Image1.ClientRect,Wmf);
end;
end.