更新区域绘制逻辑和README文档
This commit is contained in:
@@ -140,4 +140,10 @@
|
|||||||
2. 温度显示菜单下显示全局温度(可勾选)
|
2. 温度显示菜单下显示全局温度(可勾选)
|
||||||
3. 温度显示菜单下显示区域温度(可勾选)
|
3. 温度显示菜单下显示区域温度(可勾选)
|
||||||
4. 区域温度和全局温度只能二选一显示
|
4. 区域温度和全局温度只能二选一显示
|
||||||
5. 温度显示菜单下显示最高温度、平均温度和最低温度(可勾选)
|
5. 温度显示菜单下显示最高温度、平均温度和最低温度(可勾选)
|
||||||
|
|
||||||
|
### 检测配置
|
||||||
|
#### 区域绘制逻辑
|
||||||
|
1. 创建独立的叠加层图像 :专门维护一个与显示图像同尺寸的Image对象作为矩形框的叠加层
|
||||||
|
2. 分离绘制逻辑 :将临时绘制和最终绘制分离,临时矩形仍通过Paint事件显示,完成的矩形绘制到叠加层
|
||||||
|
3. 图像合并机制 :在Paint事件中先绘制叠加层,再绘制临时矩形。
|
||||||
@@ -83,6 +83,7 @@
|
|||||||
this.picBoxTemp.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
this.picBoxTemp.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||||
this.picBoxTemp.TabIndex = 0;
|
this.picBoxTemp.TabIndex = 0;
|
||||||
this.picBoxTemp.TabStop = false;
|
this.picBoxTemp.TabStop = false;
|
||||||
|
this.picBoxTemp.Paint += new System.Windows.Forms.PaintEventHandler(this.PicBoxTemp_Paint);
|
||||||
//
|
//
|
||||||
// toolStripContainer
|
// toolStripContainer
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ namespace JoyD.Windows.CS
|
|||||||
private Point _startPoint;
|
private Point _startPoint;
|
||||||
private Rectangle _currentRectangle = Rectangle.Empty;
|
private Rectangle _currentRectangle = Rectangle.Empty;
|
||||||
private bool _isDrawing = false;
|
private bool _isDrawing = false;
|
||||||
private List<Rectangle> _drawnRectangles = new List<Rectangle>();
|
private List<RegionInfo> _drawnRectangles = new List<RegionInfo>();
|
||||||
private Color _selectedColor = Color.Red;
|
private Color _selectedColor = Color.Red;
|
||||||
|
private int _regionCounter = 0;
|
||||||
|
|
||||||
public Setting()
|
public Setting()
|
||||||
{
|
{
|
||||||
@@ -112,6 +113,16 @@ namespace JoyD.Windows.CS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 存储区域信息的类,包含矩形框、颜色和序号
|
||||||
|
/// </summary>
|
||||||
|
private class RegionInfo
|
||||||
|
{
|
||||||
|
public Rectangle Rectangle { get; set; }
|
||||||
|
public Color Color { get; set; }
|
||||||
|
public int Index { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 鼠标释放事件 - 完成矩形绘制
|
/// 鼠标释放事件 - 完成矩形绘制
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -124,13 +135,23 @@ namespace JoyD.Windows.CS
|
|||||||
// 确保矩形有一定大小才添加
|
// 确保矩形有一定大小才添加
|
||||||
if (_currentRectangle.Width > 10 && _currentRectangle.Height > 10)
|
if (_currentRectangle.Width > 10 && _currentRectangle.Height > 10)
|
||||||
{
|
{
|
||||||
_drawnRectangles.Add(_currentRectangle);
|
// 增加计数器并创建新的区域信息
|
||||||
|
_regionCounter++;
|
||||||
|
RegionInfo regionInfo = new RegionInfo
|
||||||
|
{
|
||||||
|
Rectangle = _currentRectangle,
|
||||||
|
Color = _selectedColor,
|
||||||
|
Index = _regionCounter
|
||||||
|
};
|
||||||
|
|
||||||
|
_drawnRectangles.Add(regionInfo);
|
||||||
// 可以在这里添加处理矩形区域的逻辑,如保存区域信息等
|
// 可以在这里添加处理矩形区域的逻辑,如保存区域信息等
|
||||||
|
|
||||||
// 显示绘制完成的提示
|
// 显示绘制完成的提示
|
||||||
ToolStripStatusLabel statusLabel = new ToolStripStatusLabel
|
ToolStripStatusLabel statusLabel = new ToolStripStatusLabel
|
||||||
{
|
{
|
||||||
Text = string.Format("已添加检测区域: X={0}, Y={1}, 宽={2}, 高={3}",
|
Text = string.Format("已添加检测区域{0}: X={1}, Y={2}, 宽={3}, 高={4}",
|
||||||
|
_regionCounter,
|
||||||
_currentRectangle.X, _currentRectangle.Y, _currentRectangle.Width, _currentRectangle.Height)
|
_currentRectangle.X, _currentRectangle.Y, _currentRectangle.Width, _currentRectangle.Height)
|
||||||
};
|
};
|
||||||
// 如果有状态栏,可以添加到状态栏显示
|
// 如果有状态栏,可以添加到状态栏显示
|
||||||
@@ -147,9 +168,23 @@ namespace JoyD.Windows.CS
|
|||||||
private void PicBoxTemp_Paint(object sender, PaintEventArgs e)
|
private void PicBoxTemp_Paint(object sender, PaintEventArgs e)
|
||||||
{
|
{
|
||||||
// 绘制所有已完成的矩形
|
// 绘制所有已完成的矩形
|
||||||
foreach (Rectangle rect in _drawnRectangles)
|
foreach (RegionInfo region in _drawnRectangles)
|
||||||
{
|
{
|
||||||
e.Graphics.DrawRectangle(new Pen(_selectedColor, 2), rect);
|
// 使用每个区域自己的颜色绘制矩形
|
||||||
|
e.Graphics.DrawRectangle(new Pen(region.Color, 2), region.Rectangle);
|
||||||
|
|
||||||
|
// 绘制区域序号
|
||||||
|
using (Font font = new Font("Arial", 12, FontStyle.Bold))
|
||||||
|
using (SolidBrush brush = new SolidBrush(region.Color))
|
||||||
|
{
|
||||||
|
// 在矩形左上角绘制序号
|
||||||
|
Point textPosition = new Point(region.Rectangle.X + 5, region.Rectangle.Y - 15);
|
||||||
|
// 确保文本不超出控件边界
|
||||||
|
if (textPosition.Y < 0)
|
||||||
|
textPosition.Y = 5;
|
||||||
|
|
||||||
|
e.Graphics.DrawString(region.Index.ToString(), font, brush, textPosition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制当前正在绘制的矩形
|
// 绘制当前正在绘制的矩形
|
||||||
|
|||||||
Reference in New Issue
Block a user