更新UI,新增第5条:同步更新检测配置窗口的实时图像属性

This commit is contained in:
zqm
2025-11-06 10:28:35 +08:00
parent 72f9f67c85
commit 4592f25364
2 changed files with 51 additions and 5 deletions

View File

@@ -822,6 +822,15 @@ namespace JoyD.Windows.CS.Toprie
// 将全局缓冲一次性绘制到图像框的bitmap
imageBox.Image = tempImage;
// 步骤5同步更新检测配置窗口的实时图像属性
if (tempImage != null)
{
// 创建图像副本以避免线程安全问题
Image clonedImage = (Image)tempImage.Clone();
// 调用Setting窗口的方法更新实时温度图像
Setting.Form.UpdateRealTimeTemperatureImage(clonedImage);
}
if (lastImage != null)
{
Console.WriteLine($"图像更新成功: {lastImage.Width}x{lastImage.Height}");
@@ -1708,7 +1717,7 @@ namespace JoyD.Windows.CS.Toprie
Console.WriteLine("关闭相机时出错: " + ex.Message);
}
}
Setting.Form.Close();
// 取消注册事件并释放设备管理器
if (_deviceManager != null)
{
@@ -2212,11 +2221,8 @@ namespace JoyD.Windows.CS.Toprie
{
try
{
// 创建并显示检测配置窗口
Setting settingForm = new Setting();
// 显示配置窗口
settingForm.ShowDialog();
Setting.Form.ShowDialog();
}
catch (Exception ex)
{

View File

@@ -59,5 +59,45 @@ namespace JoyD.Windows.CS
// 这里可以添加每秒需要执行的代码
// 例如:更新界面数据、检查状态等
}
/// <summary>
/// 同步更新实时温度图像
/// </summary>
/// <param name="image">要显示的图像</param>
public void UpdateRealTimeTemperatureImage(Image image)
{
if (DesignMode || this.IsDisposed || this.Disposing)
return;
// 线程安全检查 - 确保在UI线程上执行
if (this.InvokeRequired)
{
try
{
this.BeginInvoke(new Action<Image>(UpdateRealTimeTemperatureImage), image);
}
catch (ObjectDisposedException)
{
// 控件已释放,忽略
}
return;
}
// 安全更新图像
if (pictureBoxTemperatureDisplay != null && !pictureBoxTemperatureDisplay.IsDisposed)
{
// 保存旧图像引用,以便设置新图像后释放
Image oldImage = pictureBoxTemperatureDisplay.Image;
// 设置新图像
pictureBoxTemperatureDisplay.Image = image;
// 释放旧图像
if (oldImage != null && oldImage != image)
{
try { oldImage.Dispose(); } catch { }
}
}
}
}
}