小免责声明:这是我第一次搞砸Forms中的Graphics,因此我对这里的概念不太熟悉
好,所以我一直在尝试创建一个应用程序来跟踪光标在整个屏幕中的位置并在其周围绘制一个椭圆。我借来的代码来自this问题(我更改了Ellipse的X和Y位置,以便在光标周围自动调整自身,而不管其大小如何),到目前为止,一切都可以正常工作。这是到目前为止的代码:
public static float width;
public static float height;
public Main(float w, float h)
{
InitializeComponent();
this.DoubleBuffered = true;
width = w;
height = h;
BackColor = Color.White;
FormBorderStyle = FormBorderStyle.None;
Bounds = Screen.PrimaryScreen.Bounds;
TopMost = true;
TransparencyKey = BackColor;
this.ShowInTaskbar = false;
timer1.Tick += timer1_Tick;
}
Timer timer1 = new Timer() { Interval = 1, Enabled = true };
protected override void OnPaint(PaintEventArgs e)
{
DrawTest(e.Graphics);
base.OnPaint(e);
}
private void DrawTest(Graphics g)
{
var p = PointToClient(Cursor.Position);
g.DrawEllipse(Pens.DeepSkyBlue, p.X - (width / 2), p.Y - (height / 2), width, height);
}
private void timer1_Tick(object sender, EventArgs e)
{
Invalidate();
}
因此,现在我希望应用程序检查椭圆区域内是否存在预先指定的颜色,如果存在,请获取距具有该颜色的光标最近的像素的位置。我到处搜索,还没有找到任何方法。
我知道其背后的逻辑是获取椭圆内的所有像素,检查颜色是否存在,并找到一种颜色最接近光标的像素,但是我无法实现它。
任何帮助将不胜感激。
low level