Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Color[,] takeScreenshot(int x=0, int y=0, int width=0, int height = 0)
- {
- if (width==0)
- width = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
- if (height==0)
- height = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
- Bitmap screenShotBMP = new Bitmap(width,
- height, PixelFormat.Format32bppArgb);
- Graphics screenShotGraphics = Graphics.FromImage(screenShotBMP);
- screenShotGraphics.CopyFromScreen(x,
- y, 0, 0, new Size(width,height),
- CopyPixelOperation.SourceCopy);
- screenShotGraphics.Dispose();
- return bitmap2imagearray(screenShotBMP);
- }
- public static Color[,] bitmap2imagearray(Bitmap b)
- {
- Color[,] imgArray = new Color[b.Width, b.Height];
- for (int y = 0; y < b.Height; y++)
- {
- for (int x = 0; x < b.Width; x++)
- {
- imgArray[x, y] = b.GetPixel(x, y);
- }
- }
- return imgArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement