Need Help with Image Resizing
Hey. In my program I have it set so that the user can load a picture. I have a track bar that I want to use so that they can resize it. My code kinda works, but I dont know if its the right way to do it, and It's slightly buggy... can anyone help improve what I have?
VB Code:
Dim resized As Bitmap
If lastTrackBarvalue < TrackBar1.Value Then 'user is making picture bigger
resized = New Bitmap(Image.FromFile(OpenImageDialog.FileName), PictureBoxNewImage.Image.Width * 1.1, PictureBoxNewImage.Image.Height * 1.1) 'each time reloads original pic to prevent distorting
ElseIf lastTrackBarvalue > TrackBar1.Value Then 'user is making picture smaller
resized = New Bitmap(Image.FromFile(OpenImageDialog.FileName), PictureBoxNewImage.Image.Width / 1.1, PictureBoxNewImage.Image.Height / 1.1) 'each time reloads original pic to prevent distorting
La
End If
If TrackBar1.Value = 0 Then 'resets to original because sometimes doesn't scale correctly
resized = New Bitmap(Image.FromFile(OpenImageDialog.FileName), pictureSize(1), pictureSize(0))
End If
LabelImageResizing.Text = "Image Resizing (" & TrackBar1.Value & ")"
PictureBoxNewImage.SizeMode = PictureBoxSizeMode.CenterImage
PictureBoxNewImage.Image = resized 'new larger image
lastTrackBarvalue = TrackBar1.Value
Part of the problem is that if you move the bar too quickly it misses some of the points to enlarge/decrease the picture. The middle part returns the original picture to its original size because if you move too fast then you can end up making the picture way too tiny and loosing the orignal dimensions.
Re: Need Help with Image Resizing
This thread should give you pretty much what you need...
http://www.vbforums.com/showthread.php?t=384835