Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2010
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. public static Color[,] takeScreenshot()
  2.         {
  3.             Bitmap screenShotBMP = new Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width,
  4.                 System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
  5.  
  6.             Graphics screenShotGraphics = Graphics.FromImage(screenShotBMP);
  7.  
  8.             screenShotGraphics.CopyFromScreen(System.Windows.Forms.Screen.PrimaryScreen.Bounds.X,
  9.                 System.Windows.Forms.Screen.PrimaryScreen.Bounds.Y, 0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Size,
  10.                 CopyPixelOperation.SourceCopy);
  11.  
  12.             screenShotGraphics.Dispose();
  13.  
  14.             return bitmap2imagearray(screenShotBMP);
  15.         }
  16.  
  17. public static Color[,] bitmap2imagearray(Bitmap b)
  18.         {
  19.             Color[,] imgArray = new Color[b.Width, b.Height];
  20.             for (int y = 0; y < b.Height; y++)
  21.             {
  22.                 for (int x = 0; x < b.Width; x++)
  23.                 {
  24.                     imgArray[x, y] = b.GetPixel(x, y);
  25.                 }
  26.             }
  27.             return imgArray;
  28.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement