シリアルポートからデータを読み取り、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();
}
画面上の画像を回転させるより効率的な方法があるかどうか疑問に思っています。あるべきだと思いますが、理解できません。