Solved

Bitmap navigating - preview window for large images

Posted on 2003-12-08
8
248 Views
Last Modified: 2010-04-05
I have a large bitmap which is placed on image in a scrroll box.

I want to have another, small image with scaled down version of the same bitmap, which will allow me to select area to be displayed in the large bitmap.

The small bitmap should have a rectangle which will represent the area displayed in the large bitmap.

Draging this rectangle within the small bitmap will result in scrolling into view corresponding area of the large bitmap.

I'm sure someone has done it already but I can't find it anywhere.

I need working example or a link to working example.
0
Comment
Question by:graga
  • 3
  • 3
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
gmayo earned 250 total points
ID: 9897828
One form, one TPaintBox (preview window), one scrollbox, and one TImage (inside the scrollbox).

procedure TForm1.PaintBox1Paint(Sender: TObject);
var
      scalex, scaley : single;
begin
      with PaintBox1.Canvas do begin
            StretchDraw(ClipRect, Image1.Picture.Graphic);
            Brush.Style := bsClear;
            Pen.Mode := pmNOT;
            scalex := PaintBox1.Width / Image1.Width;
            scaley := PaintBox1.Height / Image1.Height;
            Rectangle(Round(ScrollBox1.HorzScrollBar.Position * scalex),
                  Round(ScrollBox1.VertScrollBar.Position * scaley),
                  Round(ScrollBox1.HorzScrollBar.Position * scalex + ScrollBox1.Width * scalex),
                  Round(ScrollBox1.VertScrollBar.Position * scaley + ScrollBox1.Height * scaley));
      end;
end;

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
      ScrollBox1.HorzScrollBar.Position := Round((X / PaintBox1.Width) * Image1.Width);
      ScrollBox1.VertScrollBar.Position := Round((Y / PaintBox1.Height) * Image1.Height);
      PaintBox1.Invalidate;
end;

procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
      if (ssLeft in Shift) then PaintBox1MouseDown(Sender, mbLeft, Shift, X, Y);
end;

There's no error or sanity checking but it scrolls perfectly on mine! An improvement you may wish to make is to centre the grab box on the mouse, rather than top-left as I have done.

Geoff M.
0
 
LVL 2

Expert Comment

by:classmate
ID: 9897879
You can use the StretchBlt windows api function. I'll try to give a example...

classmate.
0
 
LVL 2

Expert Comment

by:classmate
ID: 9897899
Ok, geoff seems to have a solution, so i won't spend time on it unless there would further problems ;-)

classmate
0
 
LVL 2

Expert Comment

by:classmate
ID: 9897901
would be, that is :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:graga
ID: 9898077
Geoff,

Everything works nicely except the paintbox flickers quite badly. If you can tell me how to fix it, you will get the points, if you don't, you will get the points anyway :)

Graga
0
 

Author Comment

by:graga
ID: 9898109
Also, any quick suggestion on centering the grab box on the mouse?
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9898180
Not sure on the first one, except maybe drawing it less frequently.

The second one, well I'm at home so I can't test it. You need to subtract half the width of the rectangle off the X, equivalent for Y too. Make sure they are not negative. Do this in the PaintBoxMouseDown event.

Geoff M.
0
 

Author Comment

by:graga
ID: 9898325
Geoff,

No problem, I will find the way. Thank you for your help.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now