views:

30

answers:

1

I want to write a program that shows one PC's screen to the others... something like presentation systems. how can i take a picture from current screen?

+1  A: 

.NET exposes this functionality via the Screen (System.Windows.Forms) class.

     // the surface that we are focusing upon
     Rectangle rect = new Rectangle();

     // capture all screens in Windows
     foreach (Screen screen in Screen.AllScreens)
     {
        // increase the Rectangle to accommodate the bounds of all screens
        rect = Rectangle.Union(rect, screen.Bounds);
     }

     // create a new image that will store the capture
     Bitmap bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);

     using (Graphics g = Graphics.FromImage(bitmap))
     {
        // use GDI+ to copy the contents of the screen into the bitmap
        g.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy);
     }

     // bitmap now has the screen capture
Michael
Thank you for your help... And is there any other way to make it faster? coz copying from screen should be slow for my project...
Dr TJ
GDI+ methods are not the fastest in the world by any metric. What are you intending to do with this?
Michael