Results 1 to 2 of 2

Thread: Need Help with Image Resizing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    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:
    1. Dim resized As Bitmap
    2.  
    3.         If lastTrackBarvalue < TrackBar1.Value Then 'user is making picture bigger
    4.             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
    5.            
    6.         ElseIf lastTrackBarvalue > TrackBar1.Value Then 'user is making picture smaller
    7.             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
    8.             La
    9.         End If
    10.  
    11.         If TrackBar1.Value = 0 Then 'resets to original because sometimes doesn't scale correctly
    12.             resized = New Bitmap(Image.FromFile(OpenImageDialog.FileName), pictureSize(1), pictureSize(0))
    13.            
    14.         End If
    15.  
    16.         LabelImageResizing.Text = "Image Resizing (" & TrackBar1.Value & ")"
    17.         PictureBoxNewImage.SizeMode = PictureBoxSizeMode.CenterImage
    18.         PictureBoxNewImage.Image = resized 'new larger image
    19.         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.

  2. #2
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Need Help with Image Resizing

    This thread should give you pretty much what you need...

    http://www.vbforums.com/showthread.php?t=384835

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width