From 18c5fdf30b6c0c88f4478d40e333027926e051d3 Mon Sep 17 00:00:00 2001 From: zqm Date: Mon, 10 Nov 2025 16:50:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B8=A9=E5=B7=AE=E5=9B=BE?= =?UTF-8?q?=E7=94=BB=E6=A1=86=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98=EF=BC=9A?= =?UTF-8?q?=E7=9F=A9=E5=BD=A2=E5=8C=BA=E5=9D=90=E6=A0=87=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=92=8C=E6=93=A6=E9=99=A4=E6=A8=A1=E5=BC=8F=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E6=A1=86=E7=BB=98=E5=88=B6=E5=88=B0=E4=B8=B4=E6=97=B6=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CS/Framework4.0/Toprie/Toprie/Setting.cs | 129 +++++++++++++----- 1 file changed, 96 insertions(+), 33 deletions(-) diff --git a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs index be3130d..c90ba71 100644 --- a/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs +++ b/Windows/CS/Framework4.0/Toprie/Toprie/Setting.cs @@ -1267,33 +1267,83 @@ 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); + // 计算矩形参数:左上点是起笔方块的左上点,右下点是收笔方块的右下点 + int x = _rectangleStartPoint.X; + int y = _rectangleStartPoint.Y; + int width = currentImagePoint.X - _rectangleStartPoint.X; + int height = currentImagePoint.Y - _rectangleStartPoint.Y; + + // 确保矩形大小为正数,调整起点和大小 + if (width < 0) + { + x += width; + width = -width; + } + if (height < 0) + { + y += height; + height = -height; + } + Rectangle rect = new Rectangle(x, y, width, height); - // 创建临时位图用于双重缓冲,避免闪烁 - using (Bitmap tempBitmap = new Bitmap(_tempDiffOverlayImage)) - { - using (Graphics g = Graphics.FromImage(tempBitmap)) - { - g.SmoothingMode = SmoothingMode.AntiAlias; - g.InterpolationMode = InterpolationMode.HighQualityBicubic; - - if (_isEraseMode) - { - // 擦除模式:显示虚线预览框,不实际擦除(等待MouseUp时再擦除) + // 对于擦除模式,在临时层上绘制预览框,不影响实际的温差图 + if (_isEraseMode) + { + // 创建临时缓冲区用于绘制预览 + Bitmap bufferBitmap = null; + try + { + bufferBitmap = new Bitmap(picBoxTemp.Width, picBoxTemp.Height); + using (Graphics g = Graphics.FromImage(bufferBitmap)) + { + // 绘制背景图像 + if (picBoxTemp.Image != null) + { + g.DrawImage(picBoxTemp.Image, 0, 0, picBoxTemp.Width, picBoxTemp.Height); + } + + // 绘制温差层 + if (_tempDiffOverlayImage != null) + { + g.DrawImage(_tempDiffOverlayImage, 0, 0, picBoxTemp.Width, picBoxTemp.Height); + } + + // 绘制虚线预览框 using (Pen dashPen = new Pen(Color.White, 1)) - { + { dashPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; - g.DrawRectangle(dashPen, rect); + // 将图像坐标转换为控件坐标 + Rectangle controlRect = ImageRectangleToControlRectangle(rect); + g.DrawRectangle(dashPen, controlRect); } } - else - { - // 普通绘制模式:使用半透明填充和边框 + + // 直接在控件上绘制缓冲区内容 + using (Graphics g = picBoxTemp.CreateGraphics()) + { + g.DrawImage(bufferBitmap, 0, 0); + } + + // 防止闪烁 + return; + } + finally + { + if (bufferBitmap != null) + bufferBitmap.Dispose(); + } + } + else + { + // 普通绘制模式:使用半透明填充和边框 + using (Bitmap tempBitmap = new Bitmap(_tempDiffOverlayImage)) + { + using (Graphics g = Graphics.FromImage(tempBitmap)) + { + g.SmoothingMode = SmoothingMode.AntiAlias; + g.InterpolationMode = InterpolationMode.HighQualityBicubic; + // 创建半透明的填充颜色 Color fillColor = Color.FromArgb(128, selectedColor); @@ -1302,16 +1352,16 @@ namespace JoyD.Windows.CS // 绘制矩形边框 using (Pen pen = new Pen(selectedColor, _currentBrushSize)) - { + { g.DrawRectangle(pen, rect); } } - } - - // 将临时位图复制回温差层图像 - using (Graphics g = Graphics.FromImage(_tempDiffOverlayImage)) - { - g.DrawImage(tempBitmap, 0, 0); + + // 将临时位图复制回温差层图像 + using (Graphics g = Graphics.FromImage(_tempDiffOverlayImage)) + { + g.DrawImage(tempBitmap, 0, 0); + } } } @@ -1698,11 +1748,24 @@ 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); + // 计算矩形参数:左上点是起笔方块的左上点,右下点是收笔方块的右下点 + int x = _rectangleStartPoint.X; + int y = _rectangleStartPoint.Y; + int width = currentImagePoint.X - _rectangleStartPoint.X; + int height = currentImagePoint.Y - _rectangleStartPoint.Y; + + // 确保矩形大小为正数,调整起点和大小 + if (width < 0) + { + x += width; + width = -width; + } + if (height < 0) + { + y += height; + height = -height; + } + Rectangle rect = new Rectangle(x, y, width, height); // 只有当矩形有实际大小时才执行擦除