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

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1398
  • Karma: 108
    • View Profile
    • http://www.secretly.de
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:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2721
  • Karma: 484
    • View Profile
    • http://www.rbraz.com/
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:

Offline va!n

  • Pentium
  • *****
  • Posts: 1398
  • Karma: 108
    • View Profile
    • http://www.secretly.de
Re: How to calculate the visible area of an image?
« Reply #2 on: September 27, 2015 »
@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.

- 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: