Image queries

TatsuyA
01-03-2005, 10:21 AM
Hi guys,

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.

and

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 :/

GavinO
01-03-2005, 10: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.

noi_max
01-03-2005, 11:01 AM
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.

TatsuyA
01-03-2005, 06:02 PM
The Stretchbit function completely escapes me

zelg37
01-03-2005, 07: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):
http://www.xtremevbtalk.com/t197916.html

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:
http://www.xtremevbtalk.com/showpost.php?p=880925:

Also, you might want to spent more time studying the example that anon referenced (you said "This seems like what I need"):
"ImageViewer_with Thumbnails_and_WorkArea_Autosizing_3b.zip",
attached to this post -
http://www.xtremevbtalk.com/showpost.php?p=843199

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
Else
' The area is too tall and thin.
' Make it shorter.
hgt = wid / aspect_src
End If

' Center the image at the correct size.
pic_dst.Cls
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, _
wid, hgt
End Sub

TatsuyA
01-03-2005, 07: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.

GavinO
01-03-2005, 08: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.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum