Navigate a TImage with zoom  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 16/12/02

Tip accessed 451 times

 


Problem: View a region of any image of one map in a TImage with reduces size, without streching the image.

Put two TImage in your form, Image1 and Image2


Load any great sice image in Image1
And put this in the OnMouseDown event of Image2:

 procedure TForm1.Image2MouseDown(Sender: TObject; Button: TMouseButton;
   Shift: TShiftState; X, Y: Integer);
 var
   OrgFormPoint, CurCursorPoint, OrgCursorPoint: TPoint;

 begin
   OrgFormPoint.X := xx;
   OrgFormPoint.Y := yy;
   GetCursorpos(OrgCursorPoint);

 while (GetAsyncKeystate(VK_LBUTTON) <> 0) do
   begin
   GetCursorpos(CurCursorPoint);
   xx := OrgFormPoint.X - OrgCursorPoint.X + CurCursorPoint.X;
   yy := OrgFormPoint.Y - OrgCursorPoint.Y + CurCursorPoint.Y;
   {Borramos antes de pintar, para evitar restos perdidos}
   Image2.Canvas.FillRect(Image2.ClientRect);
   Image2.Canvas.Draw(xx,yy,Image1.picture.graphic);
   Application.processmessages;
   end;
 end;


To finish, need two global variables for store the coordinates of the image, so... we will put them in the public part of the form:


 type
   TForm1 = class(TForm)
     Image1: TImage;
     Image2: TImage;
     procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
       Shift: TShiftState; X, Y: Integer);
   private
     { Private declarations }
   public
     { Public declarations }
     xx,yy : integer;
   end;