I've been working on something where, as part of the interface, I need to have a thumbnail displayed in a picturebox. Ideally, the thumb would update to correspond when an item, file name to be exact, is clicked on in a file list box. I'm not there yet. But I used the below language to display a thumbnail of an image in the box and got it working, but the CPU useage went up to 50%+ and the main form wouldn't even fully render. So, could someone tell me what I'm doing wrong Thanks in advance for any pointers.
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
'Read the image from a file
Dim Img As Image = Image.FromFile("C:\My Documents\My Pictures\1.tif")
'I'd actually like this FromFile location to be any item clicked in the list box instead of a specifically named file as above
Dim ThumbnailWidth, ThumbNailHeight As Integer
'Adjusts the largest dimension to a set 200 pixels
'This ensures that a thumbnail will not be larger than 200 x 200 pixels
If ThumbnailWidth > ThumbNailHeight Then
ThumbnailWidth = 200
'Scale the height proportionately
ThumbNailHeight = CInt((200 / Img.Width) * Img.Height)
Else
ThumbNailHeight = 200
'Scale the width proportionately
ThumbnailWidth = CInt((200 / Img.Height) * Img.Width)
End If
'Create the Thumbnail
Img = Img.GetThumbnailImage(ThumbnailWidth, ThumbNailHeight, Nothing, Nothing)
'Display the thumbnail
'e.Graphics.DrawImage(Img, 10, 10)
PictureBox1.Image = Img
Visual Studio Express Editions21
|