Capture screen using C# and .Net 2.0

Remember old BitBlt API, for capturing screens? Here is the solution from Microsoft on .Net framework 2.0. CopyFromScreen Method – Performs a bit-block transfer of color data from the screen to the drawing surface of the Graphics.

Rectangle region = new Rectangle(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
using (Bitmap bitmap = new Bitmap(region.Width, region.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
using (Graphics bitmapGraphics = Graphics.FromImage(bitmap))
{
bitmapGraphics.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size);
Clipboard.SetImage(bitmap);
}

It only works with .Net 2.0 and more.

I developed an Application, which hosted in Codeplex, called captureit., which is using this code for capturing desktop.

MSDN : http://msdn2.microsoft.com/en-us/library/system.drawing.graphics.copyfromscreen.aspx

This entry was posted in .Net, .Net 3.0 / 3.5, Windows Forms, WPF and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>