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