Home » Category » Microsoft Visual Basic

Microsoft Visual Basic: Zoom on Picture

104| Mon, 03 Dec 2007 15:08:00 GMT| vbzoom| Comments (3)
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 :ehh: ?

Keywords & Tags: zoom, picture, microsoft, visual basic, vb

URL: http://www.programmerbase.com/visual-basic/560760/
 
«« Prev - Next »» 3 helpful answers below.
StretchBlt is what you want:

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
Private Const SRCAND = &H8800C6 ' (DWORD) dest = source AND dest
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Private Const SRCINVERT = &H660046 ' (DWORD) dest = source XOR dest
Private Const SRCPAINT = &HEE0086 ' (DWORD) dest = source OR dest

Function StretchPic(picBox As PictureBox, times As Integer) As Long
StretchBlt picBox.hdc, 0, 0, picBox.ScaleWidth * times, picBox.ScaleHeight * times, picBox.hdc, 0, 0, picBox.ScaleWidth, picBox.ScaleHeight, SRCCOPY
End Function

Use it like this:

StretchPic PictureBox, 2 '2 for 2 times the size..

Hope that helps :)

chem

chemicalnova | Mon, 03 Dec 2007 18:47:00 GMT |

Hi vbzoom and welcome to VBF! :wave:

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:

Public Sub ZoomPicture(pct As PictureBox, zoom As Double)
With pct
.Width = .Width * zoom
.Height = .Height * zoom
.PaintPicture .Picture, 0, 0, .ScaleWidth, .ScaleHeight
End With
End Sub

'usage:
Private Sub Command1_Click()
'============================

'zoom it out
ZoomPicture Picture1, 0.9

End Sub

Private Sub Command2_Click()
'============================

'zoom it in
ZoomPicture Picture1, 1.1

End Sub

rhinobull | Mon, 03 Dec 2007 18:48:00 GMT |

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

vbzoom | Mon, 03 Dec 2007 18:49:00 GMT |

Microsoft Visual Basic Hot Answers

Microsoft Visual Basic New questions

Microsoft Visual Basic Related Categories