C#的颜色判断

myvvc 2015-10-21 11:19:46
请问C#对于屏幕一个固定点,实时判断是不是红色,有没有一个详细的程序?新手学习中。
...全文
592 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzyhost 2015-10-22
  • 打赏
  • 举报
回复
GetPixel可以获取一点的具体颜值
ajianchina 2015-10-21
  • 打赏
  • 举报
回复
你拿去稍加修改就行了,搞定后别忘记结贴

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();
        }
    }
}

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧