Files
CheckDevice/Check.Main/UI/FormImageDisplay.cs
17860779768 2e46747ba9 视觉修改
2025-08-25 16:33:58 +08:00

75 lines
2.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
namespace Check.Main.UI
{
public partial class FormImageDisplay : DockContent
{
/// <summary>
/// 相机名称
/// </summary>
public string CameraName { get; set; }
/// <summary>
/// 当此显示窗口发生特定事件时如ROI裁剪触发此事件以通知外部如日志系统
/// </summary>
public event Action<string> OnDisplayEvent;
// 使用我们全新的自定义控件
private ZoomPictureBox zoomPictureBox;
public FormImageDisplay()
{
InitializeComponent();
// 实例化新的控件
zoomPictureBox = new ZoomPictureBox
{
Dock = DockStyle.Fill,
// 其他属性可以在这里设置,例如
// RectangleColor = Color.LawnGreen,
// BackgroundFillColor = Color.FromArgb(45, 45, 48)
};
this.Controls.Add(zoomPictureBox);
// 订阅自定义控件的ROI裁剪完成事件
zoomPictureBox.CroppingEnabled = false;
//zoomPictureBox.Cropped += ZoomPictureBox_Cropped;
}
/// <summary>
/// 更新显示的图像(线程安全)。
/// 此方法现在将图像设置到 ZoomPictureBox1 控件中。
/// </summary>
/// <param name="image">从相机事件传来的原始Bitmap</param>
public void UpdateImage(Bitmap image)
{
if (zoomPictureBox != null && !zoomPictureBox.IsDisposed)
{
zoomPictureBox.SetImageThreadSafe(image);
}
else
{
// 如果PictureBox已经被释放那么我们也应该释放这个多余的图像
image?.Dispose();
}
}
// 重写 Close 方法,确保在窗口关闭时,内部的控件和资源也能被妥善处理
public new void Close()
{
// 取消事件订阅,防止内存泄漏
if (zoomPictureBox != null)
{
//zoomPictureBox.Cropped -= ZoomPictureBox_Cropped;
}
base.Close();
}
}
}