Solved

Bitmap navigating - preview window for large images

Posted on 2003-12-08
8
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

617 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