Solved

Bitmap navigating - preview window for large images

Posted on 2003-12-08
8
250 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 2

Expert Comment

by:classmate
ID: 9897901
would be, that is :-)
0
 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 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