Results 1 to 4 of 4

Thread: GDI+ image zoom

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2002
    Posts
    67

    GDI+ image zoom

    Hey guys, I rarely have to deal with images so excuse my noobness. Anyway I downloaded the 101 examples from MS for vb.net and opened the GDI image manipulation.

    ' Make the PictureBox dimensions larger by 25% to effect the Zoom.
    picImage.Width = CInt(picImage.Width * 1.25)
    picImage.Height = CInt(picImage.Height * 1.25)

    This zoom works great, the only problem is that it increases the size of the picturebox. I want to ZOOM in and out on the image, leaving the picturebox the same size. Anyone have any ideas?

  2. #2
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261

    Re: GDI+ image zoom

    Originally posted by Iamthewalrus15
    Hey guys, I rarely have to deal with images so excuse my noobness. Anyway I downloaded the 101 examples from MS for vb.net and opened the GDI image manipulation.

    ' Make the PictureBox dimensions larger by 25% to effect the Zoom.
    picImage.Width = CInt(picImage.Width * 1.25)
    picImage.Height = CInt(picImage.Height * 1.25)

    This zoom works great, the only problem is that it increases the size of the picturebox. I want to ZOOM in and out on the image, leaving the picturebox the same size. Anyone have any ideas?
    I think the easiest way is to just put the picture box inside a Panel control.

    However, there's got to be a way to do this without using Windows Forms controls.

  3. #3
    Lively Member
    Join Date
    May 2003
    Posts
    68
    Panel1 is used for options
    Panel2 contain PictureBox

    PictureArray is an array with pictures ;-)

    I load the listbox with x items corresponding to X images in array


    VB Code:
    1. Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    2.         Dim Width As Integer
    3.         Dim Height As Integer
    4.         Dim Ratio As Decimal
    5.  
    6.         If ListBox1.SelectedIndex > -1 Then
    7.             If RadioButton1.Checked = True Then 'ZOOM 100%
    8.                 Height = PictureArray(ListBox1.SelectedIndex).Height
    9.                 Width = PictureArray(ListBox1.SelectedIndex).Width
    10.                 PictureBox1.Height = PictureArray(ListBox1.SelectedIndex).Height
    11.                 PictureBox1.Width = PictureArray(ListBox1.SelectedIndex).Width
    12.             Else 'ZOOM to Fit into Panel2
    13.                 PictureBox1.Height = Panel2.Height
    14.                 PictureBox1.Width = Panel2.Width
    15.  
    16.                 Ratio = PictureArray(ListBox1.SelectedIndex).width / PictureArray(ListBox1.SelectedIndex).height
    17.                 If Ratio < (PictureBox1.Width / PictureBox1.Height) Then
    18.                     Height = PictureBox1.Height
    19.                     Width = PictureBox1.Width * Ratio
    20.                 Else
    21.                     Height = PictureBox1.Height / Ratio
    22.                     Width = PictureBox1.Width
    23.                 End If
    24.             End If
    25.             PictureBox1.Image = PictureArray(ListBox1.SelectedIndex).GetThumbnailImage(Width, Height, Nothing, Nothing)
    26.             PictureBox1.Tag = ListBox1.SelectedIndex
    27.         End If
    28.     End Sub


    Hope this will help you

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    you have to use the drawimage function and only draw the visible portion of the image on the picturebox (without resizing the picturebox). Do this if you wanna be a little more efficient
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width