I would like to havo something like the navigation map of TChart, but for an image. It is: To have a big image inside a scrollbox, and, in the same form, the same image as a thumbnail with a red box showing the portion of the image showed in the scrollbox (since the full-size image is bigger than the client size of the scrollbox. The idea is to allow the user, not only to know which section of the image is observing, but also to move the redbox windows to change the portion of the image showed in the scrollbox.
For the moment, what i have is a imag showed both at full size in side the scrollbox, and in a small panel close to it. I created a shape on top of the thumbail, and this is the code i have to calculate the size of the red window marking the visible area of the image, and its position.
I added a quick and dirty demo project to help you to understand what i want to do.
My first problem is the position, since i do not know how to know the coordinates of the iupperleft corner of the section of the image showed in the scrollbox.
This is the code and where i have the problem:
procedure TForm1.RedBoxExecute(Sender: TObject);
var
imagew: integer; //Original image width at full size
imageh: integer; // Original image height at full size
windoww: integer; // frame width (scrollbox)
windowh: integer; // frame height (scrollbox)
thumbnailw: integer; //map width: the same image but small outsize the scrollbox
thumbnailh: integer; //map height: the same image but small outsize the scrollbox
redboxw: integer; // calculated redbox width
redboxh: integer; // calculated redbox height
imageX: integer; // X coordinate of the upperleft pixel of the image showed in the scrollbox
imageY: integer; // Y coordinate of the upperleft pixel of the image showed in the scrollbox
redboxX: integer; // Calculated left position of the shape
redboxY: integer; // Calculated top position of the shape
begin
imagew := image23.Picture.Bitmap.Width;
imageh := image23.Picture.Bitmap.Height;
windoww := scrollbox3.clientWidth;
windowh := scrollbox3.clientHeight;
thumbnailw := image21.Width;
thumbnailh := image21.Height;
redboxw := round((Thumbnailw*windoww) div imagew);
redboxh := round((Thumbnailh*windowh)div imageh);
shape1.Width := redboxw;
shape1.Height := redboxh;
imageX := scrollbox3.HorzScrollBar.ScrollPos; <-- this is not correct at all
imageY := scrollbox3.vertScrollBar.ScrollPos; <-- this is not correct at all
redboxX := round(( imagew*imageX) div thumbnailw);
redboxY := round(( imageh*imageY) div thumbnailh);
shape1.Left := redboxX;
shape1.Top := redboxY;
end;
I know this code is not perfect, but it is my testing code to understand what i am doing before and fsolve problems before to do it more efficient and simple.
So the question now is: How could i know the coordinates of the upperleft pixel of the image showed in the scrollbox in any moment?
Thanks!