实现温差图擦除模式下的Ctrl+左键矩形擦除功能
This commit is contained in:
@@ -638,8 +638,8 @@ namespace JoyD.Windows.CS
|
|||||||
// 退出温差图绘制状态,返回到就绪状态
|
// 退出温差图绘制状态,返回到就绪状态
|
||||||
ExitTempDiffDrawingMode();
|
ExitTempDiffDrawingMode();
|
||||||
}
|
}
|
||||||
// 温差图绘制模式下,按住Ctrl键并按下左键开始绘制矩形
|
// 温差图绘制/擦除模式下,按住Ctrl键并按下左键开始绘制矩形
|
||||||
else if (_isTempDiffDrawingMode && e.Button == MouseButtons.Left && (ModifierKeys & Keys.Control) == Keys.Control)
|
else if ((_isTempDiffDrawingMode || _isEraseMode) && e.Button == MouseButtons.Left && (ModifierKeys & Keys.Control) == Keys.Control)
|
||||||
{
|
{
|
||||||
// 初始化温差层图像(如果不存在或尺寸不匹配)
|
// 初始化温差层图像(如果不存在或尺寸不匹配)
|
||||||
if (_tempDiffOverlayImage == null ||
|
if (_tempDiffOverlayImage == null ||
|
||||||
@@ -1267,30 +1267,32 @@ namespace JoyD.Windows.CS
|
|||||||
// 获取相对于图像的当前坐标
|
// 获取相对于图像的当前坐标
|
||||||
Point currentImagePoint = ControlPointToImagePoint(e.Location);
|
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))
|
using (Bitmap tempBitmap = new Bitmap(_tempDiffOverlayImage))
|
||||||
{
|
{
|
||||||
using (Graphics g = Graphics.FromImage(tempBitmap))
|
using (Graphics g = Graphics.FromImage(tempBitmap))
|
||||||
{
|
{
|
||||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
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)
|
if (_isEraseMode)
|
||||||
{
|
{
|
||||||
// 擦除模式:使用透明色填充整个矩形区域
|
// 擦除模式:显示虚线预览框,不实际擦除(等待MouseUp时再擦除)
|
||||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
|
using (Pen dashPen = new Pen(Color.White, 1))
|
||||||
g.FillRectangle(Brushes.Transparent, rect);
|
{
|
||||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
|
dashPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
|
||||||
|
g.DrawRectangle(dashPen, rect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 普通绘制模式:使用半透明填充和边框
|
// 普通绘制模式:使用半透明填充和边框
|
||||||
// 创建半透明的填充颜色
|
// 创建半透明的填充颜色
|
||||||
Color fillColor = Color.FromArgb(128, selectedColor);
|
Color fillColor = Color.FromArgb(128, selectedColor);
|
||||||
@@ -1300,7 +1302,7 @@ namespace JoyD.Windows.CS
|
|||||||
|
|
||||||
// 绘制矩形边框
|
// 绘制矩形边框
|
||||||
using (Pen pen = new Pen(selectedColor, _currentBrushSize))
|
using (Pen pen = new Pen(selectedColor, _currentBrushSize))
|
||||||
{
|
{
|
||||||
g.DrawRectangle(pen, rect);
|
g.DrawRectangle(pen, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1308,7 +1310,7 @@ namespace JoyD.Windows.CS
|
|||||||
|
|
||||||
// 将临时位图复制回温差层图像
|
// 将临时位图复制回温差层图像
|
||||||
using (Graphics g = Graphics.FromImage(_tempDiffOverlayImage))
|
using (Graphics g = Graphics.FromImage(_tempDiffOverlayImage))
|
||||||
{
|
{
|
||||||
g.DrawImage(tempBitmap, 0, 0);
|
g.DrawImage(tempBitmap, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1683,13 +1685,40 @@ namespace JoyD.Windows.CS
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void PicBoxTemp_MouseUp(object sender, MouseEventArgs e)
|
private void PicBoxTemp_MouseUp(object sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
// 在温差图绘制模式下,松开鼠标时重置绘制状态
|
// 在温差图绘制/擦除模式下,松开鼠标时重置绘制状态
|
||||||
if (_isTempDiffDrawingMode)
|
if (_isTempDiffDrawingMode || _isEraseMode)
|
||||||
{
|
{
|
||||||
_lastDrawPoint = Point.Empty;
|
_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;
|
_isDrawingRectangle = false;
|
||||||
_rectangleStartPoint = Point.Empty;
|
_rectangleStartPoint = Point.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user