饶世树鞭杆:delphi7编程技巧与实例精解之图形图像(修正重绘变形)

来源:百度文库 编辑:九乡新闻网 时间:2024/04/28 02:24:53
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, ComCtrls, ExtCtrls, StdCtrls;typeTForm1 = class(TForm)img1: TImage;btn1: TButton;btn2: TButton;tmr1: TTimer;tb1: TTrackBar;dlgOpen1: TOpenDialog;rg1: TRadioGroup;procedure FormCreate(Sender: TObject);procedure tb1Change(Sender: TObject);procedure btn1Click(Sender: TObject);procedure tmr1Timer(Sender: TObject);procedure btn2Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;i: Integer;L,T,R,B: Integer;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);beginT:= Img1.Top;l:= img1.Left;b:= img1.Top+ img1.Height;r:= img1.Left+ img1.Width;end;procedure TForm1.tb1Change(Sender: TObject);begintmr1.Interval:= tb1.Position;end;procedure TForm1.btn1Click(Sender: TObject);vark: Integer;beginCanvas.Pen.Color:= Form1.Color;if rg1.ItemIndex<2 then beginfor k:= 0 to b do beginCanvas.MoveTo(0,k);Canvas.LineTo(r,k);end;end else if rg1.ItemIndex=2 then beginfor k:=0 to b+4 do beginCanvas.MoveTo(0,k);Canvas.LineTo(r,k);end;end;tmr1.Enabled:= True;i:= 0;end;procedure TForm1.tmr1Timer(Sender: TObject);varx,y: Integer;beginif rg1.ItemIndex=0 then beginSelf.Canvas.CopyRect(Rect(l,t+i,r,t+i+1),img1.Canvas,Rect(0,0+i,img1.Width,0+i+1));Self.Canvas.CopyRect(Rect(l,b-i,r,b-i+1),img1.Canvas,Rect(0,img1.Height-i,img1.Width,img1.Height-i+1));i:= i+1;if i>b/2-1 then tmr1.Enabled:= False;end else if rg1.ItemIndex=1 then beginSelf.Canvas.CopyRect(Rect(l,t+i*4,r,t+i*4+2),img1.Canvas,Rect(0,0+i*4,img1.Width,0+i*4+2));Self.Canvas.CopyRect(Rect(l,b-i*4-2,r,b-I*4),img1.Canvas,Rect(0,img1.Height-i*4-2,img1.Width,img1.Height-i*4));i:= i+1;if i>img1.Height/4 then tmr1.Enabled:= False;end else if rg1.ItemIndex=2 then beginfor x:= 0 to (img1.Width div 8 ) do beginfor y:= 0 to (img1.Height div 8 ) do begincase i of0: Self.Canvas.CopyRect(Rect(l+x*8,t+y*8,l+x*8+4,t+y*8+4),img1.Canvas,Rect(0+x*8,0+y*8,0+x*8+4,0+y*8+4));1: Self.Canvas.CopyRect(Rect(l+x*8+4,t+y*8+4,l+x*8+8,t+y*8+8),img1.Canvas,Rect(0+x*8+4,0+y*8+4,0+x*8+8,0+y*8+8));2: Self.Canvas.CopyRect(Rect(L+x*8,t+y*8+4,l+x*8+4,t+y*8+8),img1.Canvas,Rect(0+x*8,0+y*8+4,0+x*8+4,0+y*8+8));3: Self.Canvas.CopyRect(Rect(l+x*8+4,t+y*8,l+x*8+8,t+y*8+4),img1.Canvas,Rect(0+x*8+4,0+y*8,0+x*8+8,0+y*8+4));end;end;end;i:= i+1;if i>3 then tmr1.Enabled:= False;end;end;procedure TForm1.btn2Click(Sender: TObject);beginif not dlgOpen1.Execute then Exit;img1.Picture.LoadFromFile(dlgOpen1.FileName);T:= Img1.Top;l:= img1.Left;b:= img1.Top+ img1.Height;r:= img1.Left+ img1.Width;end;end.