Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Bitmap navigating - preview window for large images

Posted on 2003-12-08
8
Medium Priority
?
266 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 1000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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 this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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