Results 1 to 4 of 4

Thread: Zoom on Picture

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    12

    Zoom on Picture

    Is there any way in vb that when I scroll over a picture box or click on a picure box, that it would 'blow up' to a bigger image and go back to the original size once you scroll off of the picture or reclick ?

  2. #2
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Zoom on Picture

    StretchBlt is what you want:
    VB Code:
    1. Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    2. Private Const SRCAND = &H8800C6  ' (DWORD) dest = source AND dest
    3. Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
    4. Private Const SRCINVERT = &H660046       ' (DWORD) dest = source XOR dest
    5. Private Const SRCPAINT = &HEE0086        ' (DWORD) dest = source OR dest
    6.  
    7. Function StretchPic(picBox As PictureBox, times As Integer) As Long
    8. StretchBlt picBox.hdc, 0, 0, picBox.ScaleWidth * times, picBox.ScaleHeight * times, picBox.hdc, 0, 0, picBox.ScaleWidth, picBox.ScaleHeight, SRCCOPY
    9. End Function
    Use it like this:
    VB Code:
    1. StretchPic PictureBox, 2 '2 for 2 times the size..
    Hope that helps

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Zoom on Picture

    Hi vbzoom and welcome to VBF!

    Here is a small procedure that allows to zoom in/out image but KIM that the higher the resolution the more distorted it would get:
    VB Code:
    1. Public Sub ZoomPicture(pct As PictureBox, zoom As Double)
    2.     With pct
    3.         .Width = .Width * zoom
    4.         .Height = .Height * zoom
    5.         .PaintPicture .Picture, 0, 0, .ScaleWidth, .ScaleHeight
    6.     End With
    7. End Sub
    8.  
    9. 'usage:
    10. Private Sub Command1_Click()
    11. '============================
    12.  
    13.     'zoom it out
    14.     ZoomPicture Picture1, 0.9
    15.  
    16. End Sub
    17.  
    18. Private Sub Command2_Click()
    19. '============================
    20.  
    21.     'zoom it in
    22.     ZoomPicture Picture1, 1.1
    23.  
    24. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2005
    Posts
    12

    Re: Zoom on Picture

    Alright thanks....you guys helped out a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width