【发布时间】:2020-06-17 12:19:43
【问题描述】:
小免责声明:这是我第一次在表单中弄乱图形,因此我对这里的概念不太熟悉
好的,所以我一直在尝试制作一个应用程序来跟踪光标在整个屏幕中的位置并在其周围绘制一个椭圆。我借用的代码来自this 问题(我更改了椭圆的 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();
}
所以现在我希望应用程序检查椭圆区域内是否存在预先分配的颜色,如果是,则获取距具有该颜色的光标最近的像素的位置。我到处搜索,没有找到任何方法。
我知道它背后的逻辑是获取椭圆内的所有像素,检查颜色是否存在并找到该颜色最接近光标的一个像素,但我无法实现它。
任何帮助将不胜感激。
【问题讨论】:
标签: c# winforms graphics drawing gdi+