网上的取色器都不好用,自己花了一天时间写了这个,按像素取色,非常精准,很好用。 public 我的屏幕取色器()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
//设置一个定时器
timer = new Timer();
timer.Tick = TimerTick;
timer.Interval = 50;
timer.Start();
//这里注册了Ctrl Alt C 快捷键
hotKey.Regist(this.Handle, (int)HotKey.HotkeyModifiers.Control (int)HotKey.HotkeyModifiers.Alt, Keys.C, CallBack);
//MessageBox.Show("注册成功");
//初始化相关数据
InitailData();
}
/// <summary>
/// 定时器时时刷新数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void TimerTick(object sender, EventArgs e)
{
//重置图片,解决超出屏幕部分图像残留BUG
BitmapReset(bitmapSrc);
Graphics g = Graphics.FromImage(bitmapSrc);
// g.CopyFromScreen(new Point(Cursor.Position.X , Cursor.Position.Y , new Point(0, 0), new Size(imgWidth, imgHeight));
g.CopyFromScreen(new Point(Cursor.Position.X- pictureBox1.Size.Width /(2*multiple), Cursor.Position.Y - pictureBox1.Size.Height /(2 * multiple)), new Point(0, 0), pictureBox1.Size);
IntPtr dc1 = g.GetHdc();
g.ReleaseHdc(dc1);
// pictureBox2.Image = bitmapSrc;
//画一个准星标
pen.DashStyle = DashStyle.Dot;
g.DrawLine(pen,0,pictureBox1.Size.Height/ (2 * multiple),pictureBox1.Size.Width,pictureBox1.Size.Height / (2 * multiple));
g.DrawLine(pen, pictureBox1.Size.Width / (2 * multiple), 0, pictureBox1.Size.Width / (2 * multiple), pictureBox1.Size.Height);
pictureBox1.Image = MagnifierA(bitmapSrc, multiple);
pictureBox1.Image = MagnifierA(bitmapSrc, multiple);
GetPointColor(new Point(MousePosition.X,MousePosition.Y));
textBox6.Text = WindowFromPoint(Cursor.Position).ToString("X");//转换为16进制
// IntPtr ip = WindowFromPoint(Cursor.Position);
GetWindowRect(WindowFromPoint(Cursor.Position), ref rect);//h为窗口句柄
}
评论