Image resizing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyap88
    New Member
    • Jul 2007
    • 37

    Image resizing

    I m using vb 2005. I m importing a jpeg format image into form2. The image on the form will be dependant on the CustomerID. The CustomerID is taken from form1. I am also trying to allow user to select the size of the image by addding a combo box named ComboBox1.
    The following is my code:

    Form2
    --------------------------

    [CODE=vbnet]Sub Image(Byval CustomerID As String)
    Dim theImage As Image
    Dim filespec As String
    Dim scaleToPercent As Integer
    Dim imageAdjustment Percent As Decimal
    Dim adjustedImageWi dth, adjustedImageHe ight As Integer

    filespec = "C:\Documen ts and Settings\Gary\M y Documents\MP\" & CustomerID & ".jpeg"
    theImage = Image.FromFile( filespec)

    imageAdjustment Percent = (scaleToPercent / 100)


    adjustedImageWi dth = (theImage.Width * imageAdjustment Percent)
    adjustedImageHe ight = (theImage.Heigh t * imageAdjustment Percent)
    theImage = theImage.GetThu mbnailImage(adj ustedImageWidth , adjustedImageHe ight, Nothing, Nothing)

    PictureBox1.Ima ge = theImage

    Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
    scaleToPercent= ComboBox1.Text[/CODE]

    The image doesnt resize when the text in the comboxbox changed.
    Can someone edit my code so that the image resize once the integer in the comboxbox change.(default integer in combobox is 100)
  • Clanguage
    New Member
    • Jun 2007
    • 12

    #2
    I noticed that you called your sub "Image". The framework uses the "Image" keyword in the system.drawing. I don't know if it is your problem but I would definitely change the name to avoid mysterious bugs.

    Comment

    • gyap88
      New Member
      • Jul 2007
      • 37

      #3
      I have changed the name of the sub but the problem still exist.

      [CODE=vbnet]Sub DisplayImage(By val CustomerID As String)
      Dim theImage As Image
      Dim filespec As String
      Dim scaleToPercent As Integer
      Dim imageAdjustment Percent As Decimal
      Dim adjustedImageWi dth, adjustedImageHe ight As Integer

      filespec = "C:\Documen ts and Settings\Gary\M y Documents\MP\" & CustomerID & ".jpeg"
      theImage = Image.FromFile( filespec)

      imageAdjustment Percent = (scaleToPercent / 100)


      adjustedImageWi dth = (theImage.Width * imageAdjustment Percent)
      adjustedImageHe ight = (theImage.Heigh t * imageAdjustment Percent)
      theImage = theImage.GetThu mbnailImage(adj ustedImageWidth , adjustedImageHe ight, Nothing, Nothing)

      PictureBox1.Ima ge = theImage

      Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
      scaleToPercent= ComboBox1.Text[/CODE]

      I guess the problem is the failure to return scaleToPercent to sub DisplayImage.
      Can anyone help me?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Good point. You are trying to use the variable out of scope. It should be a form-level or global variable.

        Comment

        Working...