Screen Capture - Simple

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
1 post Page 1 of 1
Contributors
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Screen Capture - Simple
Codex
This is a really simple basic screen capture utility that needs no API calls. It captures the whole screen and then you can either save it into a file or show it (draw it actually) on the form. In my program that I made it uses a function similar to this, the program is called ScreenPro.

First, one global variable is declared to load a capture into a bitmap.
Code: Select all
Dim bm As Bitmap
The following is a capture function. A screen copy is made and assigned to a pointer.This is all that is needed to make an image copy of the screen.
Code: Select all
Private Sub btCapture(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click.
        Dim gr As Graphics
        bm = New Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Drawing.Imaging.PixelFormat.Format32bppArgb)
        gr = Graphics.FromImage(bm)
        gr.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, New Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
End Sub
You may choose to view the captured image. Note the use of the WindowState property.
Code: Select all
Private Sub btShow(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim newGr As Graphics = Me.CreateGraphics()
        Me.WindowState = FormWindowState.Maximized
        newGr.DrawImage(bm, New Point(0, 0))
    End Sub
Or you can save the image into a file. The following code calls the SaveFileDialog control.
Code: Select all
Private Sub btSave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SaveFileDialog1.ShowDialog()
    End Sub
Code: Select all
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
        bm.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
    End Sub
Thanks
Don't forget to +rep, comment, rate if you find this topic helpful.
Credits: VBDOTNETHEAVEN
CodexVideos
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
1 post Page 1 of 1
Return to “Tutorials”