我正在努力使我的应用程序从串行端口读取数据并更新 UI 上的仪表更有效,我想就处理 UI 更改的代码征求一些建议。我设置了一个计时器来检查发送到 COM 端口的数据,另一个计时器使用从 COM 端口接收的变量更新 UI。基本上正在发生的事情是我正在旋转仪表。这是我处理图形的代码...
void timer_Tick(object sender, EventArgs e) //Timer regulates how often the gauge is updated on the UI
{
if (pictureBox1.Image != null)
pictureBox1.Image.Dispose(); // dispose old image (you might consider reusing it rather than making a new one each frame)
Point test = new Point((int)_xCor, (int)_yCor);
Image img = new Bitmap(400, 400); // The box tht contains the image <--- Play around with this more
pictureBox1.Image = img; // Setting the img Image to the pictureBox class?
Graphics g = Graphics.FromImage(pictureBox1.Image); // G represents a drawing surface
Matrix mm1 = new Matrix();
//
mm1.RotateAt((float)(90 + (((12.5 * state) - 20.95) * 6)), new Point((int)_xrotate, (int)_yrotate), MatrixOrder.Append);
GraphicsPath gp = new GraphicsPath();
g.Transform = mm1; // transform the graphics object so the image is rotated
g.DrawImage(imgpic, test); // if the image needs to be behind the path, draw it beforehand
mm1.Dispose();// prevent possible memory leaks
gp.Dispose();// prevent possible memory leaks
g.Dispose(); // prevent possible memory leaks
pictureBox1.Refresh();
}
我想知道是否有更有效的方法可以在屏幕上旋转图像。我觉得必须有,但我想不通。