Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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!!

 

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

  • *Experts*
Posted

To scale an image use the GetThumbnailImage() method of the image:

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:

Private Function tb() As Boolean 'you can call this function whatever you want
   Return False
End Function

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...