Home : Windows Forms Viewing Controls : Find the viewable rectangle of an image using DotImage
Q10070 - HOWTO: Find the viewable rectangle of an image using DotImage
There may be times when you need to find the section of an image that is currently being viewed by the end user. To do this, you need to check the ScrollPosition, ClientSize and Zoom properties of the viewer.

Here is an example:

[C#]
// Get the viewable area of an image.
int width = Convert.ToInt32(Math.Min((this.workspaceViewer1.ClientSize.Width / this.workspaceViewer1.Zoom), (this.workspaceViewer1.Image.Width / this.workspaceViewer1.Zoom)));
int height = Convert.ToInt32(Math.Min((this.workspaceViewer1.ClientSize.Height / this.workspaceViewer1.Zoom), (this.workspaceViewer1.Image.Height / this.workspaceViewer1.Zoom)));
int left = Convert.ToInt32(Math.Abs(this.workspaceViewer1.ScrollPosition.X) / this.workspaceViewer1.Zoom);
int top = Convert.ToInt32(Math.Abs(this.workspaceViewer1.ScrollPosition.Y) / this.workspaceViewer1.Zoom);
Rectangle rc = new Rectangle(left, top, width, height);

[Visual Basic]
' Get the viewable area of an image.
Dim width As Integer = Convert.ToInt32(Math.Min((Me.workspaceViewer1.ClientSize.Width / Me.workspaceViewer1.Zoom),(Me.workspaceViewer1.Image.Width / Me.workspaceViewer1.Zoom)))
Dim height As Integer = Convert.ToInt32(Math.Min((Me.workspaceViewer1.ClientSize.Height / Me.workspaceViewer1.Zoom),(Me.workspaceViewer1.Image.Height / Me.workspaceViewer1.Zoom)))
Dim left As Integer = Convert.ToInt32(Math.Abs(Me.workspaceViewer1.ScrollPosition.X) / Me.workspaceViewer1.Zoom)
Dim top As Integer = Convert.ToInt32(Math.Abs(Me.workspaceViewer1.ScrollPosition.Y) / Me.workspaceViewer1.Zoom)
Dim rc As Rectangle = New Rectangle(left,top,width,height)
Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2017. InstantASP Ltd. All Rights Reserved