Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 picturebox image magnifyer

$
0
0
In vb.net when i click an image in a picturebox I am truing to capture the mouse position and populate a second picturebox with a zoomed in section of the image in picturebox 1.

The code seems to be working ... kind of ... It grabs a section of the image in picturebox 1 ... but not the section i click on.

Code:

Private Function magnify(ByVal position As Point)
    vert2.Clear()
    horz2.Clear()

    Dim img As New Bitmap(preciseBox.Width, preciseBox.Height)
    Dim gr As Graphics = Graphics.FromImage(img)
    Dim src As New Rectangle(position.X - 50, position.Y - 50, 100, 100)
    Dim dest As New Rectangle(0, 0, img.Width, img.Height)

    Try
        gr.DrawImage(xrayBox.Image, dest, src, GraphicsUnit.Pixel)
        img = New Bitmap(img, img.Width, img.Height)
        preciseBox.Image = img

        'Draws the crosshair on the magnify box
        vert2.Add(New Point(img.Width / 2, 0))
        vert2.Add(New Point(img.Width / 2, img.Height))
        horz2.Add(New Point(0, img.Height / 2))
        horz2.Add(New Point(img.Width, img.Height / 2))

        draw2 = True
        preciseBox.Invalidate()
    Catch ex As Exception

    End Try
    Return 0
End Function


Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>