Screen Capture Class






4.25/5 (9 votes)
The SCapture class allows an application to capture still screen images
- Download source - 3.48 KB
- Download class demo - 49.92 KB
- Download latest version
- Product website www.code2point.com
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 monitorActiveWindow
- Captures the active windowWindow
- Captures a window specified by the handle (overloaded)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 display the captured image in a PictureBox.
Me.DisplayPictureBox.Image = 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
- Updated on 08/05/08
- Added an overloadable Window method that takes a point as one of its arguments and returns the
bitmap
of a window at the point - Changed all capture methods return types from
Image
toBitmap
- Added an overloadable Window method that takes a point as one of its arguments and returns the