Solved

Bitmap navigating - preview window for large images

Posted on 2003-12-08
8
245 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

13 Experts available now in Live!

Get 1:1 Help Now