Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.NET - Picture box - Highligting Rectanle area on picturebox.

Posted on 2009-04-13
1
Medium Priority
?
722 Views
Last Modified: 2013-11-26
Dear Experts

I have a jpeg file that I am displaying in my Vb.NET application using picture box control
I have the word coordinate position of all these words present in the jpeg file.

Right now I am using the pictirebox sizemode as stretch mode. I am able to highlight the word at the correct position as per the code snippet attached below.

But, as per a new requirement, I can no longer go with stretch mode of picturebox. I have to use the zoom mode.

How do I adjust the "rect" coordinates now so that it highlights the words in zoom mode. I have tried many ways to adjust the coordinates but no success.

I appreciate any help on this.

Thanks in advance

' READ target image file
 
        Dim origImage As New Bitmap(imageFileName)
        Dim targetimage As Bitmap = New Bitmap(origImage, origImage.Width , origImage.Height )
        PictBox_Target_Height_Ratio = PictureBox1.Height / targetimage.Height
        PictBox_Target_Width_Ratio = PictureBox1.Width / targetimage.Width
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
 
 
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim highlightColor As Color = Color.FromArgb(196, 255, 255, 0)
        Dim brush As New SolidBrush(highlightColor)
        Dim rect As New Rectangle(iLeft * PictBox_Target_Width_Ratio, iTop * PictBox_Target_Height_Ratio, (iRight - iLeft) * PictBox_Target_Width_Ratio, (iBottom - iTop) * PictBox_Target_Height_Ratio)
 
        e.Graphics.FillRectangle(brush, rect)
        brush.Dispose()
    End Sub

Open in new window

0
Comment
Question by:arsmed840
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24133794
The following method will convert a point in control coordinates to a point in Image coordinates. All it does is determine the bounds of the actual image in control coordinates that the, and then maps the control coordinates to image coordinates.
Private Function GetImagePoint(ByVal pb As PictureBox, ByVal p As Point) As Point
    ' Get the Client rectangle and the scale at which the image is displayed
    Dim client As Rectangle = pb.ClientRectangle
    Dim scale As Double = Math.Min(CDbl(client.Width) / pb.Image.Width, CDbl(client.Height) / pb.Image.Height)
    
    ' Get the bounds of the image in control coordinates
    Dim imgBounds As New Rectangle(0, 0, CInt((pb.Image.Width * scale)), CInt((pb.Image.Height * scale)))
    imgBounds.X = CInt(((client.Width - imgBounds.Width) / 2))
    imgBounds.Y = CInt(((client.Height - imgBounds.Height) / 2))
    
    ' Return the point in image coordinates
    Return New Point(CInt(((p.X - imgBounds.X) / scale)), CInt(((p.Y - imgBounds.Y) / scale)))
End Function

Open in new window

0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question