### Author Topic: How to calculate the visible area of an image?  (Read 1086 times)

0 Members and 1 Guest are viewing this topic.

#### va!n

• Pentium
• Posts: 1415
• Karma: 109
##### How to calculate the visible area of an image?
« 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?
« Last Edit: September 22, 2015 by va!n »
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

#### Rbz

• Founder Member
• Posts: 2731
• Karma: 485
##### Re: How to calculate the visible area of an image?
« Reply #1 on: September 26, 2015 »
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

Challenge Trophies Won:

#### va!n

• Pentium
• Posts: 1415
• Karma: 109
##### Re: How to calculate the visible area of an image?
« Reply #2 on: September 27, 2015 »
@rbz: