0
Membuat Aplikasi Screenshot dengan VB.NET
Dengan aplikasi ini kita dimungkinkan untuk menangkap screenshot (Screen Capture) website atau screenshot setiap window dan menyimpannya menjadi sebuah image/gambar dengan menggunakan Visual Basic.Net. Berikut adalah langkah-langkah membuat aplikasi Capture Layar Monitor :
Langkah 1 : Jalankan Aplikasi Visuak Basic-mu
Langkah 2 : Buat Project Baru
Langkah 3 : Desain Form1 seperti gambar dibawah
ini.
Langkah 4 : Atur properties Kontrol yang ada di
form1 sesuai table dibawah ini.
No.
|
Kontrol
|
Properties
|
1.
|
Label
|
Name : Label1
Text : Timoresse Capture Layar Monitor
|
2.
|
Button
|
Name : btnCapture
Text : Print Layar
|
3.
|
PictureBox
|
Name : PictureBox1
|
Langkah 5 : Buat sebuat module dengan nama : Module_Screen lalu masukan script
berikut ke dalam module tersebut.
Imports System.Runtime.InteropServices Imports System.Drawing.ImagingLangkah 6 : Doubleclick Form1 kemudian masukan script berikut ini.Public Structure Window Public left As Integer Public top As Integer Public right As Integer Public bottom As Integer End Structure Public Class Module_Screen Private Declare Function BitBlt Lib "gdi32.dll" (ByVal hDestDc As IntPtr, ByVal x As Int32, ByVal y As Int32, ByVal mW As Int32, ByVal mH As Int32, ByVal hrcdc As IntPtr, ByVal xsrc As Int32, ByVal ysrc As Int32, ByVal dwrop As Int32) As Int32 Private Declare Function CreateCompatibleBitmap Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal nW As Int32, ByVal nH As Int32) As IntPtr Private Declare Function CreateCompatibleDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As IntPtr Private Declare Function DeleteDC Lib "gdi32.dll" (ByVal hdc As IntPtr) As Int32 Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As IntPtr) As Int32 Private Declare Function SelectObject Lib "gdi32.dll" (ByVal hdc As IntPtr, ByVal hObject As IntPtr) As IntPtr Private Declare Function GetDesktopWindow Lib "user32.dll" () As IntPtr Private Declare Function GetWindowDC Lib "user32.dll" (ByVal hwnd As IntPtr) As IntPtr Private Declare Function ReleaseDC Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hdc As IntPtr) As Int32 Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpRect As Window) As Int32 Public Function CaptureWindow() As Image Dim img As Image = Nothing Dim srccopy, width, heigth As Integer Dim hdcsrc, hdcdest, hbitmap, hold As IntPtr Dim windowrect As Window Dim handle As IntPtr = GetDesktopWindow() srccopy = 13369376 windowrect = New Window() hdcsrc = GetWindowDC(handle) GetWindowRect(handle, windowrect) width = windowrect.right - windowrect.left heigth = windowrect.bottom - windowrect.top hdcdest = CreateCompatibleDC(hdcsrc) hbitmap = CreateCompatibleBitmap(hdcsrc, width, heigth) hold = SelectObject(hdcdest, hbitmap) BitBlt(hdcdest, 0, 0, width, heigth, hdcsrc, 0, 0, srccopy) SelectObject(hdcdest, hold) DeleteDC(hdcdest) ReleaseDC(hdcdest, hdcsrc) img = Image.FromHbitmap(hbitmap) DeleteObject(hbitmap) Return img End Function End Class
Public Class Form1 Private Sub btnCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCapture.Click Dim capturer As New Module_Screen PictureBox1.Image = capturer.CaptureWindow() End Sub End Class
Langkah 7 : Testing Program. Sekarang tekan F5
untuk running dan testing program. Ketika tombol Print Layar di klik maka Layar
akan dicapture oleh aplikasi.
Demikian tutorial screen capture dengan visual
basic.
Semoga bermanfaat,
Terima kasih,
Download tutorial versi PDF klik disini
Posting Komentar