Advertisement
Guest User

Martheen

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