c#中怎样取得某坐标点的颜色
展开全部
// x,y 分别为x轴,y轴坐标 返回System.Drawing.Color 可以直接显示
public System.Drawing.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;
}
//定义一个定时器 获取当前坐标上的像素点颜色
private void timer_Tick(object sender, EventArgs e)
{
textBox1.Text = GetPixelColor(Cursor.Position.X, Cursor.Position.Y).R.ToString() + " " + GetPixelColor(Cursor.Position.X, Cursor.Position.Y).G.ToString() + " " + GetPixelColor(Cursor.Position.X, Cursor.Position.Y).B.ToString();
}
public System.Drawing.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;
}
//定义一个定时器 获取当前坐标上的像素点颜色
private void timer_Tick(object sender, EventArgs e)
{
textBox1.Text = GetPixelColor(Cursor.Position.X, Cursor.Position.Y).R.ToString() + " " + GetPixelColor(Cursor.Position.X, Cursor.Position.Y).G.ToString() + " " + GetPixelColor(Cursor.Position.X, Cursor.Position.Y).B.ToString();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询