Click to See Complete Forum and Search --> : Zoom


shridhark
June 30th, 2001, 01:45 AM
Hello,

I want to zoom a image in picture box. Either i can zoom to particular levels or click & drag a window in the picture box, which maximizes the selected (picked) image.

Thanks

shree
June 30th, 2001, 04:55 AM
Here's How you do it:


Dim ViewLft as Integer, ViewTop as Integer
Dim ViewWid as Integer, ViewHgt as Integer
Dim Zoom as Single

private Sub ComputeDim()
ViewWid = picView.Width / Zoom
ViewHgt = picView.Height / Zoom
If ViewWid > picImage.Width then ViewWid = picImage.Width
If ViewHgt > picImage.Height then ViewHgt = picImage.Height
End Sub

private Sub ShowImage()
picView.Cls
picView.PaintPicture picImage.Image, 0, 0, ViewWid * Zoom, ViewHgt * Zoom, ViewLft, ViewTop, ViewWid, ViewHgt
End Sub

private Sub Form_Load()
ViewLft = 0
ViewTop = 0
Zoom = 1
ComputeDim
ShowImage
End Sub

private Sub picView_MouseDown(Button as Integer, Shift as Integer, X as Single, Y as Single)
If Button = vbLeftButton then
Zoom = Zoom + 0.5
else
Zoom = Zoom - 0.5
End If
If Zoom < 0.5 then Zoom = 0.5
ComputeDim
ShowImage
End Sub




There are two pictureboxes, picImage, a hidden picturebox that contains the original image, and picView that is used to show the image. Set Autoredraw of both pictureboxes equal to True.

Using click and drag to select the zoom region is just a matter of selecting ViewTop, ViewLft, ViewWid and ViewHgt appropriately. Hope you can do it.