修复温差图画框逻辑问题:矩形区坐标调整和擦除模式预览框绘制到临时层
This commit is contained in:
@@ -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))
|
||||
// 对于擦除模式,在临时层上绘制预览框,不影响实际的温差图
|
||||
if (_isEraseMode)
|
||||
{
|
||||
using (Graphics g = Graphics.FromImage(tempBitmap))
|
||||
// 创建临时缓冲区用于绘制预览
|
||||
Bitmap bufferBitmap = null;
|
||||
try
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
|
||||
if (_isEraseMode)
|
||||
bufferBitmap = new Bitmap(picBoxTemp.Width, picBoxTemp.Height);
|
||||
using (Graphics g = Graphics.FromImage(bufferBitmap))
|
||||
{
|
||||
// 擦除模式:显示虚线预览框,不实际擦除(等待MouseUp时再擦除)
|
||||
// 绘制背景图像
|
||||
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);
|
||||
|
||||
@@ -1306,12 +1356,12 @@ namespace JoyD.Windows.CS
|
||||
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);
|
||||
|
||||
// 只有当矩形有实际大小时才执行擦除
|
||||
|
||||
Reference in New Issue
Block a user