高手帮忙一起讨论下哈

解决方案 »

  1.   

    建立一个和屏幕一样大的Bitmap.
    然后用Graphics.CopyFromScreen把屏幕拷贝上去.
    接下来要取位于(x,y)的颜色就很简单了.
    直接调用Bitmap.GetPixel (x,y);
      

  2.   

    GetPixel: 获取某一个点的颜色。
    BitBlt: 获取屏幕上一块区域的截图。
      

  3.   

    直接给你代码把
    使用timer来做..
         private void timer1_Tick(object sender, EventArgs e)
            {
                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);
                this.BackColor = _Color;
            }        [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);        [DllImport("user32.dll")]
            public static extern uint ScreenToClient(IntPtr hwnd, ref POINT p_Point);        [DllImport("gdi32.dll")]
            public static extern uint GetPixel(IntPtr hDC, int XPos, int YPos);        [DllImport("user32.dll", CharSet = CharSet.Auto)]
            public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);        [DllImport("user32.dll")]
            public static extern bool GetCursorPos(ref POINT p_Point);        [StructLayout(LayoutKind.Sequential)]
            public struct POINT
            {
                public int x;
                public int y;
            }
      

  4.   

    我写过一个,下载地址:http://download.csdn.net/source/833068
      

  5.   

    汗...
    那个方法已经可以屏幕取任意地方的颜色了.
    你再加个timer结合Cursor.Position就能
    用鼠标随时取屏幕任何地方的颜色了.
      

  6.   


    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Resources;
    using System.Reflection;namespace GetColor
    {
        public partial class Form1 : Form
        {
            private Bitmap bitmap;
            
            public Form1()
            {
                InitializeComponent();
            }        private void GetColor()
            {
                Point mouseP = Cursor.Position;
                Screen screen = Screen.PrimaryScreen;
                if (bitmap == null)
                    bitmap = new Bitmap(screen.Bounds.Width, screen.Bounds.Height);
                Graphics g = Graphics.FromImage(bitmap);
                g.CopyFromScreen(Point.Empty, Point.Empty, screen.Bounds.Size);
                g.DrawImage(bitmap, Point.Empty);
                Color c = bitmap.GetPixel(mouseP.X, mouseP.Y);
                string currColor = Convert.ToString(ColorTranslator.ToHtml(c));
                txtColor.BackColor = c;
                txtRGB.Text = Convert.ToString(ColorTranslator.ToHtml(c));        }        private void stopGetColor()
            {
                timer1.Stop();
                GetColor();
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                GetColor();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                
            }        private void btnOK_Click(object sender, EventArgs e)
            {
                timer1.Start();
                btnOK.Enabled = false;
            }        
        }
    }可以取色了就是不知道如何停止取色想双击鼠标停止取色,可是双击事件只是在窗体上双击才有效,在窗体外部不可以呀。。这个该怎么弄呀?
      

  7.   

    上面代码没写完。本来添加了一个鼠标双击时间,在里边写进去了stopGetColor(),可是不奏效
      

  8.   

     int mouseX = e.X;
     int mouseY = e.Y;
         Color pixelColor = myBitmap.GetPixel(mouseX, mouseY);
         colorbox.BackColor = pixelColor;
       
     参考