得到坐标点颜色的方法 并分解成10进制16进制
分解成10进制后进行判断颜色- Point p = new Point(MousePosition.X, MousePosition.Y);
- textBox_p.Text = p.X + "," + p.Y;//The coordinates to the window display
- IntPtr hdc = GetDC(new IntPtr(0));//Take to the device scene (0 is full screen equipment scenarios)
- int c = GetPixel(hdc, p);
- int r = (c & 0xFF);//transitionR
- int g = (c & 0xFF00) / 256;//transitionG
- int b = (c & 0xFF0000) / 65536;//transitionB
- textBox_10jz.Text = c.ToString();//10 hexadecimal color output
- textBox_16jz.Text = r.ToString("x").PadLeft(2, '0') + g.ToString("x").PadLeft(2, '0') + b.ToString("x").PadLeft(2, '0');//输出16进制颜色
- textBox_RGB.Text = r.ToString() + ',' + g.ToString() + ',' + b.ToString();//Output RGB
- textBox1.Text = this.Location.X + " " + this.Location.Y;
- pictureBox9.BackColor = Color.FromArgb(r, g, b);//Set the color box
复制代码 |