移除mask层:删除了maskImageBox相关的所有代码,包括控件声明、初始化和相关方法
This commit is contained in:
@@ -19,8 +19,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
// 是否正在接收图像
|
||||
private bool _isReceivingImage = false;
|
||||
|
||||
// 是否暂停图像更新
|
||||
private bool _isImageUpdatePaused = false;
|
||||
|
||||
|
||||
// 项目路径,用于数据文件的存取
|
||||
private string _projectPath = "";
|
||||
@@ -70,22 +69,17 @@ namespace JoyD.Windows.CS.Toprie
|
||||
|
||||
try
|
||||
{
|
||||
// 切换暂停状态
|
||||
_isImageUpdatePaused = !_isImageUpdatePaused;
|
||||
bool isPaused = pauseImageUpdateToolStripMenuItem.Text == "暂停图像更新";
|
||||
|
||||
if (_isImageUpdatePaused)
|
||||
if (isPaused)
|
||||
{
|
||||
pauseImageUpdateToolStripMenuItem.Text = "恢复图像更新";
|
||||
Console.WriteLine("图像更新已暂停");
|
||||
// 显示暂停遮罩
|
||||
UpdateMaskDisplay();
|
||||
}
|
||||
else
|
||||
{
|
||||
pauseImageUpdateToolStripMenuItem.Text = "暂停图像更新";
|
||||
Console.WriteLine("图像更新已恢复");
|
||||
// 清除暂停遮罩
|
||||
UpdateMaskDisplay();
|
||||
|
||||
// 恢复时,立即停止并重新开始图像接收,确保获取最新图像
|
||||
if (_isReceivingImage && _deviceManager != null)
|
||||
@@ -101,87 +95,6 @@ namespace JoyD.Windows.CS.Toprie
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新遮罩层的显示内容
|
||||
/// </summary>
|
||||
private void UpdateMaskDisplay()
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"UpdateMaskDisplay called, _isImageUpdatePaused: {_isImageUpdatePaused}");
|
||||
|
||||
// 在UI线程上操作
|
||||
if (InvokeRequired)
|
||||
{
|
||||
Invoke(new Action(UpdateMaskDisplay));
|
||||
return;
|
||||
}
|
||||
|
||||
if (_isImageUpdatePaused)
|
||||
{
|
||||
// 使用固定大小512*384,与图像层的src图像大小一致
|
||||
const int bitmapWidth = 512;
|
||||
const int bitmapHeight = 384;
|
||||
|
||||
Console.WriteLine($"Creating bitmap with fixed size: {bitmapWidth}x{bitmapHeight}");
|
||||
|
||||
// 创建位图
|
||||
Bitmap bitmap = new Bitmap(bitmapWidth, bitmapHeight);
|
||||
|
||||
// 直接在bitmap上绘制
|
||||
using (Graphics g = Graphics.FromImage(bitmap))
|
||||
{
|
||||
// 设置高质量绘制
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
|
||||
|
||||
// 设置更透明的背景,50是透明度值,0完全透明,255不透明
|
||||
using (Brush brush = new SolidBrush(Color.FromArgb(80, Color.Black)))
|
||||
{
|
||||
g.FillRectangle(brush, 0, 0, bitmapWidth, bitmapHeight);
|
||||
}
|
||||
|
||||
// 设置文本样式
|
||||
Font font = new Font("微软雅黑", 48, FontStyle.Bold);
|
||||
Brush textBrush = new SolidBrush(Color.White);
|
||||
StringFormat format = new StringFormat();
|
||||
format.Alignment = StringAlignment.Center;
|
||||
format.LineAlignment = StringAlignment.Center;
|
||||
|
||||
// 绘制"暂停"文字
|
||||
Console.WriteLine("Drawing '暂停' text");
|
||||
g.DrawString("暂停", font, textBrush,
|
||||
new Rectangle(0, 0, bitmapWidth, bitmapHeight), format);
|
||||
}
|
||||
|
||||
// 释放旧资源并设置新图像
|
||||
if (maskImageBox.Image != null)
|
||||
{
|
||||
maskImageBox.Image.Dispose();
|
||||
}
|
||||
maskImageBox.Image = bitmap;
|
||||
maskImageBox.Visible = true;
|
||||
Console.WriteLine("maskImageBox updated");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 清除遮罩
|
||||
Console.WriteLine("Clearing maskImageBox image");
|
||||
if (maskImageBox.Image != null)
|
||||
{
|
||||
maskImageBox.Image.Dispose();
|
||||
maskImageBox.Image = null;
|
||||
}
|
||||
maskImageBox.Visible = false; // 非暂停时隐藏遮罩
|
||||
Console.WriteLine("maskImageBox cleared");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"更新遮罩显示时出错: {ex.Message}, StackTrace: {ex.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
public Camera()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -412,7 +325,8 @@ namespace JoyD.Windows.CS.Toprie
|
||||
private void DeviceManager_ImageReceived(object sender, ImageReceivedEventArgs e)
|
||||
{
|
||||
// 如果图像更新已暂停,则不更新UI
|
||||
if (_isImageUpdatePaused)
|
||||
// 通过菜单项文本判断是否暂停
|
||||
if (pauseImageUpdateToolStripMenuItem.Text == "恢复图像更新")
|
||||
return;
|
||||
if (DesignMode) return;
|
||||
Image image = null;
|
||||
@@ -1145,15 +1059,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
/// </summary>
|
||||
private void ContextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
// 更新暂停菜单项的文本和状态
|
||||
if (_isImageUpdatePaused)
|
||||
{
|
||||
pauseImageUpdateToolStripMenuItem.Text = "恢复图像更新";
|
||||
}
|
||||
else
|
||||
{
|
||||
pauseImageUpdateToolStripMenuItem.Text = "暂停图像更新";
|
||||
}
|
||||
// 暂停菜单项的文本已经在点击事件中更新,这里无需再次更新
|
||||
if (DesignMode) return;
|
||||
try
|
||||
{
|
||||
@@ -1183,7 +1089,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
rainbow2ToolStripMenuItem.Checked = false;
|
||||
|
||||
// 尝试获取当前色彩模式并更新对应菜单项的选中状态
|
||||
if (!_isImageUpdatePaused && _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected)
|
||||
if (pauseImageUpdateToolStripMenuItem.Text == "暂停图像更新" && _deviceManager != null && _deviceManager.ConnectionStatus == ConnectionStatus.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user