01-03-2005, 11:21 AM
Two questions -
Can anyone help me out, I need to add a scrollbar to a Picture Box to enable zooming in and out of the image held within.
I'm using picture boxes to view thumbnail sized images in my form, but I don't want to use the stretch option in image boxes to scale the images down, as this will distort the images. Is there any way to lock the ratio of images in order to scale them down and fit them into a picture box without distortion?
I'm lost :/
01-03-2005, 11:54 AM
To scroll a picturebox, you probably want to have the original image full size in a hidden picturebox, and then StretchBlt the area you're viewing (calculated from the size of the display picturebox, the current zoom factor, and the scrollbar values) into the display picturebox.
As for a ratio-locked scaling, I would again recommend looking at the StretchBlt API function; you may also want to look into setting the stretch blit mode with SetStretchBltMode, to get a scaling method that works for your purposes.
01-03-2005, 12:01 PM
As far as the 'ratio-locking' thing goes, try doing a search on the forum for "aspect ratio".
There has been a lot of discussion in regards to resizing images while maintaining the original aspect ratio.
01-03-2005, 07:02 PM
The Stretchbit function completely escapes me
01-03-2005, 08:34 PM
To noi_max - TatsuyA was already told to search for "aspect ratio" by anon back in this thread (where several examples were cited):
To TatsuyA, GavinO is right. You need to use the StretchBlt API along with using SetStretchbltMode.
If you need an SetStretchBltMode/Stretchblt eample then check out (study) the code in the attachment to this post:
Also, you might want to spent more time studying the example that anon referenced (you said "This seems like what I need"):
attached to this post -
Inside Pikzel_R's Thumbnail Imageviewer is the needed "maintain aspect ratio" code :
' Copy the image from pic_src into pic_dst so
' it fits and has the same aspect ratio as the
' original picture.
Private Sub FitPictureToBox(ByVal pic_src As PictureBox, pic_dst As PictureBox)
Dim aspect_src As Single
Dim wid As Single
Dim hgt As Single
' Get the original picture's aspect ratio.
aspect_src = pic_src.ScaleWidth / pic_src.ScaleHeight
' Get the size available.
wid = pic_dst.ScaleWidth
hgt = pic_dst.ScaleHeight
' Adjust the wid/hgt ratio to match aspect_src.
If wid / hgt > aspect_src Then
' The area is too short and wide.
' Make it narrower.
wid = aspect_src * hgt
' The area is too tall and thin.
' Make it shorter.
hgt = wid / aspect_src
' Center the image at the correct size.
img1.Width = wid
img1.Height = hgt
img1.Picture = pic_src.Picture
cmdLoad.Enabled = True
cmdLoad.BackColor = &HFFFFD0
pic_dst.PaintPicture pic_src.Picture, _
(pic_dst.ScaleWidth - wid) / 2, _
(pic_dst.ScaleHeight - hgt) / 2, _
01-03-2005, 08:49 PM
Sorry I didn't make myself clear, I'm working on the scaling part of my problem at the moment.
What I meant to underline is that I didn't think this had anything to do with using a scrollbar to zoom an image in and out, held within a picture box. Is there not a simpler way to do this?
EDIT- I didn't necessarily mean simpler, I just didn't think it applied to that part of the problem
I must also apologise for seeming obtuse, I find it annoying myself when people call for help in any of the forums I help in and cannot think for themselves, I didn't mean to come across that way. The fact is I'm more design/less programmer minded and I'm having difficulties with this part of my studies.
01-03-2005, 09:27 PM
The stretchblt function is providing the scaling element between your full-size source image (in a hidden picture box) and the zoomed region of the image that it being displayed in the display picturebox. The source for the stretchblt function will be the hidden box, with the source coordinates, width, and height parameters describing the rectangle of the image to be zoomed in on (the field of view of the display, so to speak). The destination will be the display picturebox, with the destination coordinates set to (0,0) and the width and height set to the scalewidth and scaleheight of the display box, respectively.