Guest User

Untitled

a guest
Jun 23rd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Runtime.InteropServices;
  4.  
  5. sealed class Win32
  6. {
  7. [DllImport("user32.dll")]
  8. static extern IntPtr GetDC(IntPtr hwnd);
  9.  
  10. [DllImport("user32.dll")]
  11. static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
  12.  
  13. [DllImport("gdi32.dll")]
  14. static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
  15.  
  16. static public System.Drawing.Color GetPixelColor(int x, int y)
  17. {
  18. IntPtr hdc = GetDC(IntPtr.Zero);
  19. uint pixel = GetPixel(hdc, x, y);
  20. ReleaseDC(IntPtr.Zero, hdc);
  21. Color color = Color.FromArgb((int)(pixel & 0x000000FF),
  22. (int)(pixel & 0x0000FF00) >> 8,
  23. (int)(pixel & 0x00FF0000) >> 16);
  24. return color;
  25. }
  26. }
Add Comment
Please, Sign In to add comment