Results 1 to 12 of 12

Thread: Screen image capture class.

Threaded View

  1. #1

    Thread Starter
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Screen Image Capture Class

    I created the SCapture class to allow us capture still images from the screen. The SCapture class uses some Api methods to implement the capture. The main reason I used the Api functions such as BitBlt to build the bitmap image because the .Net way of capturing an image does not capture transparent image as transparent; check it here.

    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 or a point (overloaded).
    • Control– Captures a control of a window specified by a handle or a point (overloaded).
    • ScreenRectangle– Captures a rectangle image from the screen.
    • All methods can capture images that include the cursor. New

    Using the code:
    vb Code:
    1. Private Sub ControlButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ControlButton.Click
    2.     Try
    3.         'Capture the image of this button including the cursor.
    4.         Dim img As Image = SCapture.Control(Control.MousePosition, True)
    5.         'Save the captured image.
    6.         img.Save(filePath, Drawing.Imaging.ImageFormat.Png)
    7.         'Also display the captured image in a PictureBox.
    8.         Me.DisplayPictureBox.BackgroundImage = img
    9.     Catch ex As Exception
    10.         'Show a MessageBox if the capture of image failed.
    11.         MessageBox.Show("Failed to capture the control!" _
    12.         & Environment.NewLine & ex.Message, "Capture Error!", _
    13.         MessageBoxButtons.OK, MessageBoxIcon.Error)
    14.     End Try
    15. End Sub
    Author name:
    Arman Ghazanchyan

    Update history:

    09/17/2007
    1. I added a method DisplayMonitor that implements a monitor image capture.
    2. Also the FullScreen method is improved to capture a single image of all monitors that are installed on the system.

    06/29/2008
    1. I added an ability to all methods to capture images that include the cursor.

    07/21/2008
    1. I just changed the class name from ICapture to SCapture.

    08/05/2008
    1. I added an overloadable Window method that takes a point as one of its arguments and returns the bitmap of a window at the point.
    2. Changed all capture methods return types from Image to Bitmap.

    You can check the demo project for the examples of how to capture images with various methods.

    Please feel free to rate this post , comment and notify me about any problem associated with it.

    Download the latest version here
    Attached Images Attached Images  
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width