Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. public Bitmap CaptureFromScreen(Rectangle rect)
  2. {
  3. Bitmap bmpScreenCapture = null;
  4.  
  5. if (rect == Rectangle.Empty)//capture the whole screen
  6. {
  7. bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
  8. Screen.PrimaryScreen.Bounds.Height);
  9. }
  10. else // just the rect
  11. {
  12. bmpScreenCapture = new Bitmap(rect.Width,rect.Height);
  13. }
  14.  
  15. Graphics p = Graphics.FromImage(bmpScreenCapture);
  16.  
  17. if (rect == Rectangle.Empty)
  18. { // captuer the whole screen
  19. p.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
  20. Screen.PrimaryScreen.Bounds.Y,
  21. 0, 0,
  22. bmpScreenCapture.Size,
  23. CopyPixelOperation.SourceCopy);
  24.  
  25. }
  26. else // cut a spacific rectangle
  27. {
  28. p.CopyFromScreen(rect.X,
  29. rect.Y,
  30. 0, 0,
  31. rect.Size,
  32. CopyPixelOperation.SourceCopy);
  33.  
  34. }
  35.  
  36. return bmpScreenCapture;
  37. }
  38.  
  39. public Color GetColorFromScreen(Point p)
  40. {
  41. Rectangle rect = new Rectangle(p, new Size(2, 2));
  42.  
  43. Bitmap map = CaptureFromScreen(rect);
  44.  
  45. Color c = map.GetPixel(0, 0);
  46.  
  47. map.Dispose();
  48.  
  49. return c;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement