|
|
#1 |
|
Lively Member
Join Date: May 06
Posts: 120
![]() |
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?
|
|
|
|
|
|
#2 |
|
PowerPoster
Join Date: Mar 04
Location: New Amsterdam
Posts: 21,118
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: zoom in and zoom out
See if this sample works for you.
__________________
Microsoft MVP - Visual Basic 2006-2010 Why VB clears the clipboard on startup and how to avoid it? . Filtering Arrays . Save File To Database . Extract File From Database . Extract picture from database without using hard drive . Change Menu BackColor . How to use MS Flexgrid . Make Frame Transparent . The Easiest Way to Create an NT Service With VB6 . How to comment blocks of code in VB5 and VB6 . How to find and replace missing members of control array Visual Basic 6.0 On-Line Documentation . Connection Strings |
|
|
|
|
|
#3 | |
|
Lively Member
Join Date: May 06
Posts: 120
![]() |
Re: zoom in and zoom out
Quote:
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. |
|
|
|
|
|
|
#4 |
|
Code Giver
Join Date: Jan 03
Location: Argentina
Posts: 3,639
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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. |
|
|
|
|
|
#5 | |
|
PowerPoster
Join Date: Mar 04
Location: New Amsterdam
Posts: 21,118
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: zoom in and zoom out
Quote:
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.
__________________
Microsoft MVP - Visual Basic 2006-2010 Why VB clears the clipboard on startup and how to avoid it? . Filtering Arrays . Save File To Database . Extract File From Database . Extract picture from database without using hard drive . Change Menu BackColor . How to use MS Flexgrid . Make Frame Transparent . The Easiest Way to Create an NT Service With VB6 . How to comment blocks of code in VB5 and VB6 . How to find and replace missing members of control array Visual Basic 6.0 On-Line Documentation . Connection Strings |
|
|
|
|
|
|
#6 |
|
Lively Member
Join Date: May 06
Posts: 120
![]() |
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.
|
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|