我正在使用眼動儀在窗體上顯示眼球運動。這些動作一直閃爍很多,所以我發現我可以使用BufferedGraphics,除了眼動開始之外,它們都可以正常工作,它將窗體從原始顏色變成黑色。這是代碼。希望有人能幫助!爲什麼渲染車削黑色
private void button2_Click(object sender, EventArgs e)
{
var host = new Host();
var gazeStream = host.Streams.CreateGazePointDataStream();
gazeStream.GazePoint((x, y, ts)
=> drawCircle(new PointF((float)x, (float)y)));
}
delegate void SetCallback(PointF point);
private void drawCircle(PointF point)
{
float x = point.X;
float y = point.Y;
if (this.InvokeRequired)
{
SetCallback d = new SetCallback(drawCircle);
this.Invoke(d, new object[] { point });
}
else
{
SolidBrush semiTransBrush = new SolidBrush(Color.Coral);
Pen pen = new Pen(Color.Aquamarine, 2);
BufferedGraphicsContext currentContext;
BufferedGraphics myBuffer;
// Gets a reference to the current BufferedGraphicsContext
currentContext = BufferedGraphicsManager.Current;
// Creates a BufferedGraphics instance associated with Form1, and with
// dimensions the same size as the drawing surface of Form1.
myBuffer = currentContext.Allocate(this.CreateGraphics(),this.DisplayRectangle);
myBuffer.Graphics.DrawEllipse(pen, x, y, 100, 100);
myBuffer.Graphics.FillEllipse(semiTransBrush, x, y, 100, 100);
// Renders the contents of the buffer to the specified drawing surface.
myBuffer.Render(this.CreateGraphics());
myBuffer.Dispose();
}
您可以在圖片中看到的圓圈顯示控件後面這似乎是形式沒有了嗎?
嘗試'myBuffer.Graphics.Clear(this.BackColor);'繪製形狀之前 - 也就是如果你沒有別的形式 –
我有單選按鈕,並在窗體上的標籤上。控件仍然顯示。它看起來幾乎像表單的背景已被刪除,而不是僅僅改變顏色 – user8370201
問題的代碼在哪裏?顯示更多關於方法的詳細信息 –