To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Mar 13th, 2007, 02:06 PM   #1
junlo
Lively Member
 
Join Date: May 06
Posts: 120
junlo is an unknown quantity at this point (<10)
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?
junlo is offline   Reply With Quote
Old Mar 13th, 2007, 09:58 PM   #3
junlo
Lively Member
 
Join Date: May 06
Posts: 120
junlo is an unknown quantity at this point (<10)
Re: zoom in and zoom out

Quote:
Originally Posted by RhinoBull
See if this sample works for you.
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.
junlo is offline   Reply With Quote
Old Mar 14th, 2007, 03:10 AM   #4
jcis
Code Giver
 
jcis's Avatar
 
Join Date: Jan 03
Location: Argentina
Posts: 3,639
jcis is a splendid one to behold (700+)jcis is a splendid one to behold (700+)jcis is a splendid one to behold (700+)jcis is a splendid one to behold (700+)jcis is a splendid one to behold (700+)jcis is a splendid one to behold (700+)jcis is a splendid one to behold (700+)jcis is a splendid one to behold (700+)
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.
jcis is offline   Reply With Quote
Old Mar 14th, 2007, 07:43 AM   #5
RhinoBull
PowerPoster
 
RhinoBull's Avatar
 
Join Date: Mar 04
Location: New Amsterdam
Posts: 21,118
RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)RhinoBull is a name known to all (1000+)
Re: zoom in and zoom out

Quote:
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.
RhinoBull is offline   Reply With Quote
Old Mar 14th, 2007, 08:18 AM   #6
junlo
Lively Member
 
Join Date: May 06
Posts: 120
junlo is an unknown quantity at this point (<10)
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)
junlo is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:16 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.