Senin, 21 Maret 2011

0

[VB.NET] Membuat Program Screen Capture Sederhana

  • Senin, 21 Maret 2011
  • Nurkholish Ardi Firdaus
  • Share
  • Banyak sekali software screen capture di luar sana, mulai dari yang berbayar hingga yang gratisan. Software ini berguna untuk menangkap/menjepret gambar yang ada di layar. Sebenarnya jika anda membuatnya juga bisa. Postingan saya kali ini akan mendeskripsikan bagaimana membuat program screen capture sederhana. Mari kita berangkat......




    Dalam membuatnya, saya menggunakan 2 Form:

    1. Form Pertama

    Deklarasi:
    Form1
      Name: Main
      Size: 290; 65
      FormBorderStyle: FixedSingle
      MaximumBox: False
      Text: Crowja Screen Capture
    Label1
      Name: Label1
      Text: &Time (s)
    TextBox1
      Name: txtTime
    Button1
      Name: &Capture

    Desain Form Untuk Form Pertama:




    Source Code Untuk Class Form Pertama:

    Imports System.Threading
    Imports System.Drawing
    Public Class Main
        Public scrCap As Bitmap          ' buat bitmap yang akan digunakan
        Public recScreen As Rectangle    ' buat kotakan layar
        Public grapScreen As Graphics    ' buat object drawing GDI+ 
    
        Private Sub txtTime_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTime.KeyPress
            If Not (Asc(e.KeyChar) >= Asc("0") And Asc(e.KeyChar) <= Asc("9")) Then e.KeyChar = Nothing ' menyaring key yang ditekan (hanya numerik)
        End Sub
    
        Private Sub cmdCap_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCap.Click
            Me.Opacity = 0
            For i = Val(txtTime.Text) To 0 Step -1
                Thread.Sleep(1000)
                Me.Text = "Capturing in " & i & " s"
            Next
            Me.Text = "Crowja Screen Capture"
            Me.ShowInTaskbar = False
            CaptureScreen()
            Me.Opacity = 1
            Me.ShowInTaskbar = True
        End Sub
    
        Private Sub CaptureScreen()
            recScreen = Screen.PrimaryScreen.Bounds
            scrCap = New System.Drawing.Bitmap(recScreen.Width, recScreen.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            grapScreen = Graphics.FromImage(scrCap)
            grapScreen.CopyFromScreen(recScreen.X, recScreen.Y, 0, 0, recScreen.Size, CopyPixelOperation.SourceCopy)
            Me.Hide()
            FormPreview.Visible = True
            FormPreview.Show()
        End Sub
    End Class
    ' 2011 Crowja
     
    2. Form Kedua

    Deklarasi:
    Form2
        Name: FormPreview
        FormBorderStyle: FixedSingle
        MaximizeBox: False
        Text: Crowja Screen Capture
    Button1
        Name: cmdSaveAs
        Text: &Save As
    Button2
        Name: cmdClose
        Text: &Close
    PictureBox1
        Name: picPreview
        SizeMode: StretchImage

    Desain Form Untuk Form Kedua:


    Source Code Untuk Class Form Kedua:


    Public Class FormPreview
        Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
            Me.Close()
        End Sub
    
        Private Sub FormPreview_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            Main.Show()
        End Sub
    
        Private Sub FormPreview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            picPreview.Image = Main.scrCap
        End Sub
    
        Private Sub cmdSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveAs.Click
            Dim oDialogSave As New SaveFileDialog
            With oDialogSave
                .Filter = "Bitmap File | *.bmp"
                .CheckPathExists = True
                .OverwritePrompt = True
                .ShowDialog()
                If (.FileName <> "") Then
                    picPreview.Image.Save(.FileName)
                End If
            End With
        End Sub
    End Class
    ' 2011 Crowja

    Bagi Sobat yang agak malas membuatnya, seperti biasa saya menyertakan source code nya untuk di download:


    Crowja-Coderz
    Jangan Lupa Komentar Yaa..
    Related Posts Plugin for WordPress, Blogger...

    0 Komentar Untuk “[VB.NET] Membuat Program Screen Capture Sederhana”

    Posting Komentar

    Berikan komentar positif tentang artikel yang sederhana ini niscaya sobat akan mendapatkan balasannya. Hehehe

    Subscribe