Languages » VB.NET » Visual Basic .NET     Intermediate License: The Code Project Open License (CPOL)

Screen Capture Class

By VBDT

The SCapture class allows an application to capture still screen images
VB (VB 8.0, VB), .NET (.NET, .NET 2.0), Visual Studio (VS2005, Visual Studio), Dev

Posted: 21 Jul 2008
Updated: 21 Jul 2008
Views: 1,012
2 votes for this Article.
Popularity: 0.90 Rating: 3.00 out of 5
1 vote, 50.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
0 votes, 0.0%
4
1 vote, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

The SCapture class allows an application to capture a still screen image. It also provides a functionality to include the cursor in the image.

Class shared methods

  • FullScreen - Captures the full screen (all monitors in a single image).
  • DisplayMonitor - Captures a display monitor.
  • ActiveWindow – Captures the active window.
  • Window – Captures a window specified by the handle.
  • Control – Captures a control of a window specified by a handle or a point (overloaded).
  • ScreenRectangle – Captures a rectangle image from the screen.

Background

The class differs from some other similar articles that provide classes to capture an image from the screen by giving the application ability to capture transparent windows images. The core of the class is based on some Api methods.

Using the code

A small example to capture a button control image from a form by using a point on the button.

Private Sub ControlButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ControlButton.Click
    Try
        'Capture the image of this button including the cursor.
        Dim img As Image = SCapture.Control(Control.MousePosition, True)
        'Save the captured image.
        img.Save(filePath, Drawing.Imaging.ImageFormat.Png)
        'Also dispay the captured image on a PictureBox.
        Me.DisplayPictureBox.BackgroundImage = img
    Catch ex As Exception
        'Show a MessageBox if the capture of image failed.
        MessageBox.Show("Failed to capture the control!" _
        & Environment.NewLine & ex.Message, "Capture Error!", _
        MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub        

History

Originally posted on 07/21/08

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

VBDT



Occupation: Software Developer (Senior)
Location: United States United States

Discussions and Feedback

Comment 0 messages have been posted for this article. Visit http://www.codeproject.com/KB/vb/SCapture.aspx to post and view comments on this article, or click here to get a print view with messages.

PermaLink | Privacy | Terms of Use
Last Updated: 21 Jul 2008
Editor:
Copyright 2008 by VBDT
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project