Search Tools Links Login

Resizing a picture algorithm

It resizes any size picture in a picturebox into another any size picturebox. I made this to show an algorithm of resizing a picture.

Original Author: Peter Rosconi


startingPic As PictureBox, destinationPic As PictureBox


Must have two picture boxes the 'starting picture box' must have a picture already loaded into it.

Side Effects

Not the most efficient way to resize a picture.


'pretty much straight forward just load a picture
'  into 'startingPic' and call this sub
Public Sub ResizePicture(startingPic As PictureBox, destinationPic As PictureBox)
'the horz. and vert. ratios
ratioX = startingPic.ScaleWidth / destinationPic.ScaleWidth
ratioY = startingPic.ScaleHeight / destinationPic.ScaleHeight
'for stats
theTimer = Timer
'go through the startingPic's pixels
For x = 0 To startingPic.ScaleWidth Step ratioX
For y = 0 To startingPic.ScaleHeight Step ratioY
  'get the color of the startingPic
  theColor = startingPic.Point(x, y)
  'find the corresponding x and y values
  ' for the resized destination pic
  realX = ratioX ^ -1 * x
  realY = ratioY ^ -1 * y
  destinationPic.PSet (realX, realY), theColor
Next y
Next x
MsgBox "It took " & Timer - theTimer & " seconds to increase the horizontal size by " & ratioX ^ -1 & " and the vertical size by " & ratioY ^ -1 & "."
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 73 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.