|
-
Mar 13th, 2007, 02:06 PM
#1
Thread Starter
Lively Member
zoom in and zoom out
how to write the code to zoom in or zoom out the picture? can anybody provide the code on zoom in or out function?
-
Mar 13th, 2007, 02:14 PM
#2
Re: zoom in and zoom out
See if this sample works for you.
-
Mar 13th, 2007, 09:58 PM
#3
Thread Starter
Lively Member
Re: zoom in and zoom out
 Originally Posted by RhinoBull
this sample is zoom in or zoom out the picture box' size.
what i want is zoom in or zoom out the actual picture's size which i loaded but the picture box's size is still maintain.
Last edited by junlo; Mar 13th, 2007 at 10:07 PM.
-
Mar 14th, 2007, 03:10 AM
#4
Re: zoom in and zoom out
Something similar
Code:
Private mPic As Picture
Private mWidth As Single, mHeight As Single
Private Sub Form_Load()
Set mPic = LoadPicture("D:\pic1.JPG") '(Add the Path to your Picture here)
mWidth = Picture1.ScaleX(mPic.Width, vbHimetric, Picture1.ScaleMode)
mHeight = Picture1.ScaleY(mPic.Height, vbHimetric, Picture1.ScaleMode)
Picture1.AutoRedraw = True
Picture1.PaintPicture mPic, 0, 0
End Sub
Private Sub Command1_Click()
ZoomPicture Picture1, 0.9
End Sub
Private Sub Command2_Click()
ZoomPicture Picture1, 1.1
End Sub
Public Sub ZoomPicture(pct As PictureBox, zoom As Double)
pct.Cls
mWidth = mWidth * zoom
mHeight = mHeight * zoom
pct.PaintPicture mPic, 0, 0, mWidth, mHeight
End Sub
Last edited by jcis; Mar 14th, 2007 at 03:13 AM.
-
Mar 14th, 2007, 07:43 AM
#5
Re: zoom in and zoom out
 Originally Posted by junlo
this sample is zoom in or zoom out the picture box' size...
But that was done intentionally or it will look sort of unfinished otherwise.
If you want to keep the orginal controls size place your main picturebox (without the borders) into another picturebox (with the borders) that can work like container.
You will resize picturebox that displays picture but container will stay unchanged.
-
Mar 14th, 2007, 08:18 AM
#6
Thread Starter
Lively Member
Re: zoom in and zoom out
Code:
Private Sub Form_Load()
Dim lPic As Picture
Me.Picture1.AutoRedraw = True
Set lPic = LoadPicture("C:\YourPicture.jpg") 'Use the correct path and filename here
ResizePicture Me.Picture1, lPic
End Sub
Private Sub ResizePicture(pBox As PictureBox, pPic As Picture)
Dim lWidth As Single, lHeight As Single
Dim lnewWidth As Single, lnewHeight As Single
'Clear the Picture in the PictureBox
pBox.Picture = Nothing
'Clear the Image in the Picturebox
pBox.Cls
'Get the size of the Image, but in the same Scale than the scale used by the PictureBox
lWidth = pBox.ScaleX(pPic.Width, vbHimetric, pBox.ScaleMode)
lHeight = pBox.ScaleY(pPic.Height, vbHimetric, pBox.ScaleMode)
'If image Width > pictureBox Width, resize Width
If lWidth > pBox.ScaleWidth Then
lnewWidth = pBox.ScaleWidth 'new Width = PB width
lHeight = lHeight * (lnewWidth / lWidth) 'Risize Height keeping proportions
Else
lnewWidth = lWidth 'If not, keep the original Width value
End If
'If the image Height > The pictureBox Height, resize Height
If lHeight > pBox.ScaleHeight Then
lnewHeight = pBox.ScaleHeight 'new Height = PB Height
lnewWidth = lnewWidth * (lnewHeight / lHeight) 'Risize Width keeping proportions
Else
lnewHeight = lHeight 'If not, use the same value
End If
'add resized and centered to Picturebox
pBox.PaintPicture pPic, (pBox.ScaleWidth - lnewWidth) / 2, _
(pBox.ScaleHeight - lnewHeight) / 2, _
lnewWidth, lnewHeight
'Update the Picture with the new image if you need it
Set pBox.Picture = pBox.Image
End Sub
You can add ResizePicture sub in a module (declare it Public) if you want.
i use code above,but came out an error "object variable or with block variable not set" and point to the line code(red color)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|