Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: va!n on September 22, 2015
-
I have some trouble with some basic math and cant find any infos / math about it on the web.
I am loading and showing a bitmap inside a window and i can zoom it in/out (ImageWidth * ZoomFactor), where ZoomFactor range from int 1 to 32.
A smaller scaled version of the original bitmap will be shown as preview in a so called navigation window (like photoshop).
At this point i know following values/infos:
- The client width and height of the window (where the image will be drawn)
- Original image width and height
- width and height of the scaled/zoomed image (imageWidth * zoomFactor)
- width and height of the preview area (where the scaled down image will be drawn)
- width and height of the image preview (navigation window)
- The zoomFactor ( 1 == 100% | 2 == 200 %... )
QUESTION:
The bitmap preview should show a rect of the area, we are zoomed in / which is visible. (see screenshot from photoshop)
How to calculate the (red) rect of the visible area?
Something i tried (just as example):
ClientWidth = 1024 | ImageWidth = 1280 -----> (100/(ImageWidth*zoomFactor)) * ClientWidth == 80
Also 80 % of the original imageWidth ((1280/100)*80) are visible in this example.
Any idea where to find infos on the web or whats the name of this to search?
-
Not sure if I understand your question but I would try to save the first coordinate top / left and just subtract from bottom / right
width = right - left
height = bottom - top
(https://i-msdn.sec.s-msft.com/dynimg/IC412667.png)
-
@rbz:
Thanks for your reply.
Calcuating the width and height of an area or an image isnt the problem ;)
If you know Photoshop for example, there is a "navigation window" for the artist to see the visible area of the image (if you are zoomed in). The visible area will be drawn in the "navigation window" with a red border/box.
If the image is zoomed (as like on the screenshot), i have problems how to calculature the area of the red box in the navigation window.