新しい画像がカメラ バッファーに読み込まれるたびに、ライブ カメラから画像を更新する画像ボックスを含むアプリがあります。私の問題は、このライブ フィードを取得するたびに、アプリ全体が非常に遅くなり、(場合によっては) 応答しなくなることです。基本的にすべてのイメージング手順を実行し、新しい画像を画像ボックスに入れる別のスレッドがあります。私は問題を解決する方法に行き詰まっています。誰かアイデアがあるかどうか疑問に思っていますか? 必要なコードの種類はわかりませんImageUpdated
が、画像を取得して に貼り付けるイベントは次のとおりPictureBox
です。助けてくれてありがとう!
void CurrentCamera_ImageUpdated(object sender, EventArgs e)
{
try
{
lock (CurrentCamera.image)
{
if (CurrentCamera != null && CurrentCamera.image != null && !changeCam)
{
videoImage = CurrentCamera.videoImage;
if (CurrentCamera.videoImage != null && this.IsHandleCreated)
{
Bitmap tmp = new Bitmap(CurrentCamera.image.Width, CurrentCamera.image.Height);
//Creates a crosshair on the image
using (Graphics g = Graphics.FromImage(tmp))
{
g.DrawImage(CurrentCamera.image, new Point(0, 0));
g.DrawLine(crosshairPen, new Point(CurrentCamera.image.Width / 2, 0), new Point(CurrentCamera.image.Width / 2, (CurrentCamera.image.Height)));
g.DrawLine(crosshairPen, new Point(0, CurrentCamera.image.Height / 2), new Point((CurrentCamera.image.Width), CurrentCamera.image.Height / 2));
g.DrawEllipse(crosshairPen, (CurrentCamera.image.Width / 2) - crosshairRadius, (CurrentCamera.image.Height / 2) - crosshairRadius, crosshairRadius * 2, crosshairRadius * 2);
}
pictureBox1.BeginInvoke((MethodInvoker)delegate
{
pictureBox1.Image = tmp;
});
}
}
}
}
catch { }
}