Api functions:
Copy codeThe Code is as follows:
1. [DllImport ("user32.dll")] // device fetch scenario
2. private static extern IntPtr GetDC (IntPtr hwnd); // return the device scenario handle
3. [DllImport ("gdi32.dll")] // obtain the specified vertex color
4. private static extern int GetPixel (IntPtr hdc, Point p );
Main Methods:
Copy codeThe Code is as follows:
Timer tim = new Timer ();
Tim. Interval = 1;
Tim. Tick + = delegate
{
Point p = new Point (MousePosition. X, MousePosition. Y); // obtains the coordinates of the top Point.
IntPtr hdc = GetDC (new IntPtr (0); // device scenario (0 is a full screen device scenario)
Int c = GetPixel (hdc, p); // you can specify the vertex color.
Int r = (c & 0xFF); // convert R
Int g = (c & 0xFF00)/256; // convert G
Int B = (c & 0xFF0000)/65536; // convert B
PictureBox1.BackColor = Color. FromArgb (r, g, B );
};
Tim. Start ();
Demo: