resize image on import

jimday1982

Member
Joined
Jul 30, 2003
Messages
22
Location
Va Beach
I was wondering if anyone knows of a way to specify the size of an image on import into my program. For instance, if the user imports a 500 x 500 picture, i need it to fit my 100x100 picture box. I know about the autosize property and all that, but there are more operations that are going to be associated with the picture box that make autosize impossible to use. The code I have for importing the pictures is below. Thanks for your help!!

Code:
Private Sub b101clicksub(ByVal sender As System.Object, ByVal e As System.EventArgs)
        With ofd51
            .CheckFileExists = True
            .CheckPathExists = True
            .Filter = "Images|*.bmp;*.tiff;*.jpg;*.jpeg;*.png;"
            .Multiselect = False
            .ShowHelp = False
            .Title = "Select an Image"
        End With

        If ofd51.ShowDialog() = DialogResult.OK Then
            Dim tmpBMP As New Bitmap(ofd51.FileName)
            gp51.Image = tmpBMP
        End If
    End Sub
 
To scale an image use the GetThumbnailImage() method of the image:
Code:
Dim b As new Bitmap("image path")
b = b.GetThumbnailImage(width, height, New Image.GetThumbnailImageAbort(AddressOf tb), IntPtr.Zero)
picturebox1.Image = b
And then you must add a delegate for the third argument:
Code:
Private Function tb() As Boolean you can call this function whatever you want
    Return False
End Function
 
Back
Top