实现暂停功能时在InfoImage中显示暂停字样
This commit is contained in:
@@ -93,12 +93,75 @@ namespace JoyD.Windows.CS.Toprie
|
||||
{
|
||||
pauseImageUpdateToolStripMenuItem.Text = "恢复图像更新";
|
||||
Console.WriteLine("图像更新已暂停");
|
||||
|
||||
// 在InfoImage中绘制暂停字样
|
||||
lock (_infoImageLock)
|
||||
{
|
||||
// 释放之前的InfoImage资源
|
||||
if (_infoImage != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_infoImage.Dispose();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"释放InfoImage资源异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 创建新的InfoImage并绘制暂停字样
|
||||
_infoImage = new Bitmap(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
using (Graphics g = Graphics.FromImage(_infoImage))
|
||||
{
|
||||
// 设置半透明背景
|
||||
using (SolidBrush brush = new SolidBrush(Color.FromArgb(128, Color.Black)))
|
||||
{
|
||||
g.FillRectangle(brush, 0, 0, BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
}
|
||||
|
||||
// 绘制暂停字样
|
||||
using (Font font = new Font("Arial", 48, FontStyle.Bold))
|
||||
using (SolidBrush textBrush = new SolidBrush(Color.Red))
|
||||
{
|
||||
StringFormat format = new StringFormat();
|
||||
format.Alignment = StringAlignment.Center;
|
||||
format.LineAlignment = StringAlignment.Center;
|
||||
g.DrawString("暂停", font, textBrush, new RectangleF(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT), format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置显示信息标志并更新UI
|
||||
_isDisplayingInfo = true;
|
||||
UpdateImageOnUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
pauseImageUpdateToolStripMenuItem.Text = "暂停图像更新";
|
||||
Console.WriteLine("图像更新已恢复");
|
||||
|
||||
// 清除InfoImage和显示标志
|
||||
lock (_infoImageLock)
|
||||
{
|
||||
if (_infoImage != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_infoImage.Dispose();
|
||||
_infoImage = null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"释放InfoImage资源异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
_isDisplayingInfo = false;
|
||||
|
||||
// 立即更新UI
|
||||
UpdateImageOnUI();
|
||||
|
||||
// 恢复时,立即停止并重新开始图像接收,确保获取最新图像
|
||||
if (_isReceivingImage && _deviceManager != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user