还原温差图绘制和擦除功能,仅保留单击时的方形绘制

This commit is contained in:
zqm
2025-11-11 10:43:53 +08:00
parent 5da04406f4
commit f67bd812b3

View File

@@ -1375,49 +1375,6 @@ namespace JoyD.Windows.CS
} }
} }
/// <summary>
/// 在两点之间绘制方形路径,用于模拟方形画笔效果
/// </summary>
private void DrawLineAsRectangles(Graphics g, Brush brush, Point startPoint, Point endPoint, int halfSize)
{
// 计算两点之间的距离和方向
int dx = Math.Abs(endPoint.X - startPoint.X);
int dy = Math.Abs(endPoint.Y - startPoint.Y);
int sx = startPoint.X < endPoint.X ? 1 : -1;
int sy = startPoint.Y < endPoint.Y ? 1 : -1;
int err = dx - dy;
int e2;
Point currentPoint = startPoint;
// 使用Bresenham算法遍历直线上的每个点
while (true)
{
// 在当前点绘制方形
g.FillRectangle(brush,
currentPoint.X - halfSize,
currentPoint.Y - halfSize,
halfSize * 2,
halfSize * 2);
// 检查是否到达终点
if (currentPoint.X == endPoint.X && currentPoint.Y == endPoint.Y)
break;
e2 = 2 * err;
if (e2 > -dy)
{
err -= dy;
currentPoint.X += sx;
}
if (e2 < dx)
{
err += dx;
currentPoint.Y += sy;
}
}
}
/// <summary> /// <summary>
/// 将控件坐标转换为图像坐标 /// 将控件坐标转换为图像坐标
/// </summary> /// </summary>
@@ -1703,22 +1660,23 @@ namespace JoyD.Windows.CS
if (_lastDrawPoint == Point.Empty) if (_lastDrawPoint == Point.Empty)
{ {
_lastDrawPoint = imagePoint; _lastDrawPoint = imagePoint;
// 绘制起始点的形(擦除区域) // 绘制起始点的形(擦除区域)
int halfSize = adjustedBrushSize / 2; int radius = adjustedBrushSize / 2;
g.FillRectangle(Brushes.Transparent, g.FillEllipse(Brushes.Transparent,
imagePoint.X - halfSize, imagePoint.X - radius,
imagePoint.Y - halfSize, imagePoint.Y - radius,
adjustedBrushSize, adjustedBrushSize,
adjustedBrushSize); adjustedBrushSize);
} }
else else
{ {
// 绘制方形路径进行擦除 // 使用透明色绘制粗线条进行擦除,使用调整后的画笔大小
int halfSize = adjustedBrushSize / 2; using (Pen pen = new Pen(Color.Transparent, adjustedBrushSize))
using (SolidBrush brush = new SolidBrush(Color.Transparent))
{ {
// 计算两点之间的直线区域,并绘制方形 pen.StartCap = LineCap.Round;
DrawLineAsRectangles(g, brush, _lastDrawPoint, imagePoint, halfSize); pen.EndCap = LineCap.Round;
pen.LineJoin = LineJoin.Round;
g.DrawLine(pen, _lastDrawPoint, imagePoint);
} }
// 更新上一个点 // 更新上一个点
_lastDrawPoint = imagePoint; _lastDrawPoint = imagePoint;
@@ -1740,23 +1698,18 @@ namespace JoyD.Windows.CS
if (_lastDrawPoint == Point.Empty) if (_lastDrawPoint == Point.Empty)
{ {
_lastDrawPoint = imagePoint; _lastDrawPoint = imagePoint;
// 绘制起始点的 // 绘制起始点的
int halfSize = _currentBrushSize / 2; int radius = _currentBrushSize / 2;
g.FillRectangle(new SolidBrush(selectedColor), g.FillEllipse(new SolidBrush(selectedColor),
imagePoint.X - halfSize, imagePoint.X - radius,
imagePoint.Y - halfSize, imagePoint.Y - radius,
_currentBrushSize, _currentBrushSize,
_currentBrushSize); _currentBrushSize);
} }
else else
{ {
// 绘制方形路径 // 绘制连线
int halfSize = _currentBrushSize / 2; g.DrawLine(pen, _lastDrawPoint, imagePoint);
using (SolidBrush brush = new SolidBrush(selectedColor))
{
// 计算两点之间的直线区域,并绘制方形
DrawLineAsRectangles(g, brush, _lastDrawPoint, imagePoint, halfSize);
}
// 更新上一个点 // 更新上一个点
_lastDrawPoint = imagePoint; _lastDrawPoint = imagePoint;
} }