Possible g.Transform usage

Les 281 Reputation points
2021-02-01T07:02:51.497+00:00

I have the following output onto a picturebox that I would like to home in on a specific part of the image so I can zoom in on that part. I am not familiar much with the Transform property and am wondering if I am approaching what I am trying to achieve properly. If you look at the following picture that whole image is on a picturebox surface and the square black box I placed there I would like to focus in on it and have it fill the picturebox in essence zooming in62248-graph.jpg. Hopefully I am making myself clear.

Thanks

Les

Developer technologies | VB
0 comments No comments
{count} votes

Answer accepted by question author
  1. Xingyu Zhao-MSFT 5,381 Reputation points
    2021-02-04T02:47:01.467+00:00

    Hi @Les ,

    how to we find all posts that I have made here like the old site did?

    You can see them in 'Activity'.
    63806-1.png

    For picture zoom, also check : https://www.codeproject.com/Articles/21097/PictureBox-Zoom
    In Visual Basic, the code looks like:

        Private _ZoomFactor As Integer  
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
            TrackBar1.Minimum = 1  
            TrackBar1.Maximum = 3  
            TrackBar1.Value = 2  
            _ZoomFactor = TrackBar1.Value  
            PictureBox2.SizeMode = PictureBoxSizeMode.StretchImage  
            PictureBox1.Image = Image.FromFile("your picture path")  
        End Sub  
        Private Sub TrackBar1_ValueChanged(sender As Object, e As EventArgs) Handles TrackBar1.ValueChanged  
            _ZoomFactor = TrackBar1.Value  
            Label1.Text = String.Format("x{0}", _ZoomFactor)  
        End Sub  
      
        Private Sub PictureBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles PictureBox1.MouseMove  
            If PictureBox1.Image Is Nothing Then Return  
            UpdateZoomedImage(e)  
        End Sub  
        Private Sub UpdateZoomedImage(ByVal e As MouseEventArgs)  
            Dim zoomWidth As Integer = PictureBox2.Width / _ZoomFactor  
            Dim zoomHeight As Integer = PictureBox2.Height / _ZoomFactor  
            Dim halfWidth As Integer = zoomWidth / 2  
            Dim halfHeight As Integer = zoomHeight / 2  
            Dim tempBitmap As Bitmap = New Bitmap(zoomWidth, zoomHeight, PixelFormat.Format24bppRgb)  
            Dim bmGraphics As Graphics = Graphics.FromImage(tempBitmap)  
            bmGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic  
            bmGraphics.DrawImage(PictureBox1.Image, New Rectangle(0, 0, zoomWidth, zoomHeight), New Rectangle(e.X - halfWidth, e.Y - halfHeight, zoomWidth, zoomHeight), GraphicsUnit.Pixel)  
            PictureBox2.Image = tempBitmap  
            bmGraphics.DrawLine(Pens.Black, halfWidth + 1, halfHeight - 4, halfWidth + 1, halfHeight - 1)  
            bmGraphics.DrawLine(Pens.Black, halfWidth + 1, halfHeight + 6, halfWidth + 1, halfHeight + 3)  
            bmGraphics.DrawLine(Pens.Black, halfWidth - 4, halfHeight + 1, halfWidth - 1, halfHeight + 1)  
            bmGraphics.DrawLine(Pens.Black, halfWidth + 6, halfHeight + 1, halfWidth + 3, halfHeight + 1)  
            bmGraphics.Dispose()  
            PictureBox2.Refresh()  
        End Sub  
    

    Result of my test.
    63812-gif.gif
    Hope it could be helpful.

    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Castorix31 91,501 Reputation points
    2021-02-01T07:24:54.953+00:00

    You can zoom by resizing an image with DrawImage
    Like in the second example in MSDN at Cropping and Scaling Images in GDI+


  2. Les 281 Reputation points
    2021-02-03T20:11:36.807+00:00

    No one has answered this post. I need to know what I am doing thanks

    Les

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.