实现温差图擦除模式下的Ctrl+左键矩形擦除功能
This commit is contained in:
@@ -638,8 +638,8 @@ namespace JoyD.Windows.CS
|
||||
// 退出温差图绘制状态,返回到就绪状态
|
||||
ExitTempDiffDrawingMode();
|
||||
}
|
||||
// 温差图绘制模式下,按住Ctrl键并按下左键开始绘制矩形
|
||||
else if (_isTempDiffDrawingMode && e.Button == MouseButtons.Left && (ModifierKeys & Keys.Control) == Keys.Control)
|
||||
// 温差图绘制/擦除模式下,按住Ctrl键并按下左键开始绘制矩形
|
||||
else if ((_isTempDiffDrawingMode || _isEraseMode) && e.Button == MouseButtons.Left && (ModifierKeys & Keys.Control) == Keys.Control)
|
||||
{
|
||||
// 初始化温差层图像(如果不存在或尺寸不匹配)
|
||||
if (_tempDiffOverlayImage == null ||
|
||||
@@ -1267,6 +1267,13 @@ namespace JoyD.Windows.CS
|
||||
// 获取相对于图像的当前坐标
|
||||
Point currentImagePoint = ControlPointToImagePoint(e.Location);
|
||||
|
||||
// 计算矩形参数
|
||||
int x = Math.Min(_rectangleStartPoint.X, currentImagePoint.X);
|
||||
int y = Math.Min(_rectangleStartPoint.Y, currentImagePoint.Y);
|
||||
int width = Math.Abs(currentImagePoint.X - _rectangleStartPoint.X);
|
||||
int height = Math.Abs(currentImagePoint.Y - _rectangleStartPoint.Y);
|
||||
Rectangle rect = new Rectangle(x, y, width, height);
|
||||
|
||||
// 创建临时位图用于双重缓冲,避免闪烁
|
||||
using (Bitmap tempBitmap = new Bitmap(_tempDiffOverlayImage))
|
||||
{
|
||||
@@ -1275,19 +1282,14 @@ namespace JoyD.Windows.CS
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
|
||||
// 计算矩形参数
|
||||
int x = Math.Min(_rectangleStartPoint.X, currentImagePoint.X);
|
||||
int y = Math.Min(_rectangleStartPoint.Y, currentImagePoint.Y);
|
||||
int width = Math.Abs(currentImagePoint.X - _rectangleStartPoint.X);
|
||||
int height = Math.Abs(currentImagePoint.Y - _rectangleStartPoint.Y);
|
||||
Rectangle rect = new Rectangle(x, y, width, height);
|
||||
|
||||
if (_isEraseMode)
|
||||
{
|
||||
// 擦除模式:使用透明色填充整个矩形区域
|
||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
|
||||
g.FillRectangle(Brushes.Transparent, rect);
|
||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
|
||||
// 擦除模式:显示虚线预览框,不实际擦除(等待MouseUp时再擦除)
|
||||
using (Pen dashPen = new Pen(Color.White, 1))
|
||||
{
|
||||
dashPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||
g.DrawRectangle(dashPen, rect);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1683,13 +1685,40 @@ namespace JoyD.Windows.CS
|
||||
/// </summary>
|
||||
private void PicBoxTemp_MouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
// 在温差图绘制模式下,松开鼠标时重置绘制状态
|
||||
if (_isTempDiffDrawingMode)
|
||||
// 在温差图绘制/擦除模式下,松开鼠标时重置绘制状态
|
||||
if (_isTempDiffDrawingMode || _isEraseMode)
|
||||
{
|
||||
_lastDrawPoint = Point.Empty;
|
||||
// 结束矩形绘制
|
||||
if (_isDrawingRectangle)
|
||||
// 结束矩形绘制/擦除
|
||||
if (_isDrawingRectangle && picBoxTemp.Image != null)
|
||||
{
|
||||
// 如果是擦除模式,在MouseUp时一次性擦除矩形区域
|
||||
if (_isEraseMode)
|
||||
{
|
||||
// 获取相对于图像的当前坐标
|
||||
Point currentImagePoint = ControlPointToImagePoint(e.Location);
|
||||
|
||||
// 计算矩形参数
|
||||
int x = Math.Min(_rectangleStartPoint.X, currentImagePoint.X);
|
||||
int y = Math.Min(_rectangleStartPoint.Y, currentImagePoint.Y);
|
||||
int width = Math.Abs(currentImagePoint.X - _rectangleStartPoint.X);
|
||||
int height = Math.Abs(currentImagePoint.Y - _rectangleStartPoint.Y);
|
||||
Rectangle rect = new Rectangle(x, y, width, height);
|
||||
|
||||
// 只有当矩形有实际大小时才执行擦除
|
||||
if (width > 0 && height > 0)
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(_tempDiffOverlayImage))
|
||||
{
|
||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
|
||||
g.FillRectangle(Brushes.Transparent, rect);
|
||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
|
||||
}
|
||||
// 触发重绘
|
||||
picBoxTemp.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
_isDrawingRectangle = false;
|
||||
_rectangleStartPoint = Point.Empty;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user