好久不做这个东西了!!http://174.36.135.46/hk/?fromuid=32156

解决方案 »

  1.   

         public static Color GetColor()
            {
                POINT _Point = new POINT();
                GetCursorPos(ref _Point);
                IntPtr _Hwnd = WindowFromPoint((uint)_Point.x, (uint)_Point.y);
                IntPtr _DC = GetDC(_Hwnd);
                ScreenToClient(_Hwnd, ref _Point);
                uint _ColorLong = GetPixel(_DC, _Point.x, _Point.y);    
                Color _Color = Color.FromArgb((int)_ColorLong & 0xFF, (int)(_ColorLong & 0xFF00) / 256, (int)(_ColorLong & 0xFF0000) / 65536);            ReleaseDC(_Hwnd, _DC);            return _Color;        }        [StructLayout(LayoutKind.Sequential)]
            public struct POINT
            {
                public int x;
                public int y;
            }
            [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);        [DllImport("gdi32.dll")]
            public static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);        [DllImport("user32.dll")]
            public static extern uint ScreenToClient(IntPtr hwnd, ref POINT p_Point);        [DllImport("user32.dll")]
            public static extern bool GetCursorPos(ref POINT p_Point);        [DllImport("user32.dll")]
            public static extern IntPtr WindowFromPoint(uint x_point, uint y_point);        [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr GetDC(IntPtr hWnd);
      

  2.   

     [DllImport("user32.dll")]
            static extern IntPtr GetDC(IntPtr hwnd);        [DllImport("user32.dll")]
            static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);        [DllImport("gdi32.dll")]
            static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);        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();
            }测试已通过
      

  3.   

    Cursor.Position.X, Cursor.Position.Y 表示鼠标所在的当前位置,你只要把这里换成你要的点的坐标就可以了
      

  4.   

    用鼠标钩子(hook)也可以得到
      

  5.   

    private void tmr_Tick(object sender, EventArgs e)
            {            // 创建显示器的DC            IntPtr hdlDisplay = CreateDC("DISPLAY", null, null, IntPtr.Zero);            // 从指定设备的句柄创建新的 Graphics 对象            Graphics gfxDisplay = Graphics.FromHdc(hdlDisplay);            // 创建只有一个象素大小的 Bitmap 对象            Bitmap bmp = new Bitmap(1, 1, gfxDisplay);            // 从指定 Image 对象创建新的 Graphics 对象            Graphics gfxBmp = Graphics.FromImage(bmp);            // 获得屏幕的句柄            IntPtr hdlScreen = gfxDisplay.GetHdc();            // 获得位图的句柄            IntPtr hdlBmp = gfxBmp.GetHdc();            // 把当前屏幕中鼠标指针所在位置的一个象素拷贝到位图中            BitBlt(hdlBmp, 0, 0, 1, 1, hdlScreen, MousePosition.X, MousePosition.Y, 13369376);            // 释放屏幕句柄            gfxDisplay.ReleaseHdc(hdlScreen);            // 释放位图句柄            gfxBmp.ReleaseHdc(hdlBmp);            lblColor.BackColor = bmp.GetPixel(0, 0); // 获取像素的颜色            txtArgb.Text = "0x" + lblColor.BackColor.ToArgb().ToString("x").ToUpper();
                TxtBox_RGB.Text = lblColor.BackColor.R.ToString() + "," + lblColor.BackColor.G.ToString() + "," + lblColor.BackColor.B.ToString();
                gfxDisplay.Dispose();
                gfxBmp.Dispose();            bmp.Dispose(); // 释放 bmp 所使用的资源        }        private void txtArgb_KeyPress(object sender, KeyPressEventArgs e)
            {
                // 当按下ESC键时,确定所取的颜色ARGB值
                // 注意:只有当窗体处于激活状态时才有效
                if (e.KeyChar == (char)Keys.Escape)
                {
                    tmr.Enabled = false;
                    this.Location = formLoc;
                    this.TopMost = false;
                    txtArgb.SelectAll();
                }
            }        private void Form1_MouseEnter(object sender, EventArgs e)
            {
                if (this.Location == ptLeftBottom) //窗体在左下角
                {
                    this.Location = ptRightBottom;
                }
                else if (this.Location == ptRightBottom) // 窗体在右下角
                {
                    this.Location = ptLeftBottom;
                }
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        private void txtArgb_TextChanged(object sender, EventArgs e)
            {        }
        }
    }
      

  6.   

    GetPixel是相当的慢,如果做图象识别,这个是绝对不能用的。
      

  7.   

    <<WINDOWS 程序设计>>里有详细例程
      

  8.   

    用过SPY++吧,
    介绍个工具ColorSPY.exe, 非常好用,还支持缩放http://download.csdn.net/source/305251