请问C#对于屏幕一个固定点,实时判断是不是红色,有没有一个详细的程序?新手学习中。
------解决思路----------------------
你拿去稍加修改就行了,搞定后别忘记结贴
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace 工程1
{
public partial class Form1 : Form
{
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetDC(int hwnd);
[DllImport("gdi32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int GetPixel(int hdc, int X, int y);
private struct POINTAPI //确定坐标
{
private int X;
private int y;
}
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)] //确定坐标
private static extern int ReleaseDC(int hwnd, int hdc);
POINTAPI P; //确定坐标
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int ScreenToClient(int hwnd, ref POINTAPI lpPoint);
[DllImport("user32", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true)]
private static extern int WindowFromPoint(int xPoint, int yPoint);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double blue;
double green;
double red;
int hD;
int h;
int c;
int a;
int b;
a = Convert.ToInt32(textBox1.Text );
b = Convert.ToInt32(textBox2.Text);
h = WindowFromPoint(a, b);
hD = GetDC(h);
ScreenToClient(h, ref P);
c = GetPixel(hD, a, b);
red = c % 256;
green = (c / 256) % 256;
blue = c / 256 / 256;
textBox3.Text =red.ToString ();
textBox4.Text =blue.ToString ();
textBox5.Text = green.ToString();
}
//timer控件的Enabled属性设为true
private void timer1_Tick(object sender, EventArgs e)
{
textBox6.Text ="X=" +System.Windows.Forms.Control.MousePosition.X.ToString()+" "+ "Y="+ System.Windows.Forms.Control.MousePosition.Y.ToString();
}
}
}
------解决思路----------------------
GetPixel可以获取一点的具体颜值