Tras agregar la biblioteca de clases KeyboardAndMouse vamos a agregar la siguiente función para obtener el color del píxel seleccionado:
[System.Runtime.InteropServices.DllImport("gdi32.dll")] static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); [System.Runtime.InteropServices.DllImport("user32.dll")] static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc); [System.Runtime.InteropServices.DllImport("user32.dll")] static extern IntPtr GetDC(IntPtr hwnd); public static Color GetPixelColor(int x, int y) { IntPtr hdc = GetDC(IntPtr.Zero); uint pixel = GetPixel(hdc, x, y); ReleaseDC(IntPtr.Zero, hdc); Color color = Color.FromArgb((int)(pixel & 0x000000FF), (int)(pixel & 0x0000FF00) >> 8, (int)(pixel & 0x00FF0000) >> 16); return color; }
Con ello, jugando con el evento MouseChanged de la clase KeyboardAndMouse.Mouse.MouseActions, podremos recoger el color de cada pulsación del usuario. Os dejo un vídeo con un ejemplo:
El código lo dejo aquí:
No hay comentarios:
Publicar un comentario