Cara Zoom In Gambar di Picture Box–VB6

Friday, October 17, 2014

Setelah lama tidak posting di Blog Belajar VB kali ini saya akan membahas cara men-zoom in gambar pada VB6, tanpa banyak basa-basi langsung saja ke langkah-langkahnya:

- Buka VB6 nya kemudian pilih standard exe.

- Masukan 2 buah Picture Box dan 1 buah shape, untuk memasukan shape klik dahulu picture box 1 dan letakan shape di sana, ingat jangan membuat shape di luar picturebox1.

image

- Masukan sebuah gambar pada picturebox1 di picture pada properties.

- Setelah itu masukan sintak berikut di general:

Option Explicit

- Kemudian sintak berikut di Form Load untuk membuat skala pixel:

Private Sub Form_Load()
    Me.ScaleMode = 3
    Picture1.ScaleMode = 3
    Picture2.ScaleMode = 3
    Picture1.AutoRedraw = True
    Picture1.Picture = Picture1.Image
End Sub

- dan sintak berikut di Picture1 MouseMove, digunakan saat mouse bergeser dan posisi down, serta mensnapshot picture1 ke picture2:

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    On Error Resume Next 
    If Button = 1 Then 
        If (X > 0) And (Y > 0) And (X < Picture1.ScaleWidth) And (Y < Picture1.ScaleWidth) Then
            Shape1.Left = X - (Shape1.Width / 2)
            Shape1.Top = Y - (Shape1.Height / 2)  
            DoEvents
            Call Picture2.PaintPicture(Picture1, 0, 0, Picture1.Width, Picture1.Height, Shape1.Left, Shape1.Top, Shape1.Width, Shape1.Height)
            DoEvents
        End If
    End If
End Sub

- Serta sintak berikut untuk di Picture1 mouseUp:

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    DoEvents
    Call Picture2.PaintPicture(Picture1, 0, 0, Picture1.Width, Picture1.Height, Shape1.Left, Shape1.Top, Shape1.Width, Shape1.Height)
End Sub

- Setelah itu jalankan programnya dan geserkan shape1 nya. Maka otomatis gambar akan ter-zoom ke picture2.

image

Sekian tutorialnya semoga bermanfaat.

0 comments:

Post a Comment