修改温差图绘制和擦除区域为方形
This commit is contained in:
@@ -1375,6 +1375,49 @@ 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>
|
||||||
@@ -1660,23 +1703,22 @@ namespace JoyD.Windows.CS
|
|||||||
if (_lastDrawPoint == Point.Empty)
|
if (_lastDrawPoint == Point.Empty)
|
||||||
{
|
{
|
||||||
_lastDrawPoint = imagePoint;
|
_lastDrawPoint = imagePoint;
|
||||||
// 绘制起始点的圆形(擦除区域)
|
// 绘制起始点的方形(擦除区域)
|
||||||
int radius = adjustedBrushSize / 2;
|
int halfSize = adjustedBrushSize / 2;
|
||||||
g.FillEllipse(Brushes.Transparent,
|
g.FillRectangle(Brushes.Transparent,
|
||||||
imagePoint.X - radius,
|
imagePoint.X - halfSize,
|
||||||
imagePoint.Y - radius,
|
imagePoint.Y - halfSize,
|
||||||
adjustedBrushSize,
|
adjustedBrushSize,
|
||||||
adjustedBrushSize);
|
adjustedBrushSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 使用透明色绘制粗线条进行擦除,使用调整后的画笔大小
|
// 绘制方形路径进行擦除
|
||||||
using (Pen pen = new Pen(Color.Transparent, adjustedBrushSize))
|
int halfSize = adjustedBrushSize / 2;
|
||||||
{
|
using (SolidBrush brush = new SolidBrush(Color.Transparent))
|
||||||
pen.StartCap = LineCap.Round;
|
{
|
||||||
pen.EndCap = LineCap.Round;
|
// 计算两点之间的直线区域,并绘制方形
|
||||||
pen.LineJoin = LineJoin.Round;
|
DrawLineAsRectangles(g, brush, _lastDrawPoint, imagePoint, halfSize);
|
||||||
g.DrawLine(pen, _lastDrawPoint, imagePoint);
|
|
||||||
}
|
}
|
||||||
// 更新上一个点
|
// 更新上一个点
|
||||||
_lastDrawPoint = imagePoint;
|
_lastDrawPoint = imagePoint;
|
||||||
@@ -1698,18 +1740,23 @@ namespace JoyD.Windows.CS
|
|||||||
if (_lastDrawPoint == Point.Empty)
|
if (_lastDrawPoint == Point.Empty)
|
||||||
{
|
{
|
||||||
_lastDrawPoint = imagePoint;
|
_lastDrawPoint = imagePoint;
|
||||||
// 绘制起始点的圆形
|
// 绘制起始点的方形
|
||||||
int radius = _currentBrushSize / 2;
|
int halfSize = _currentBrushSize / 2;
|
||||||
g.FillEllipse(new SolidBrush(selectedColor),
|
g.FillRectangle(new SolidBrush(selectedColor),
|
||||||
imagePoint.X - radius,
|
imagePoint.X - halfSize,
|
||||||
imagePoint.Y - radius,
|
imagePoint.Y - halfSize,
|
||||||
_currentBrushSize,
|
_currentBrushSize,
|
||||||
_currentBrushSize);
|
_currentBrushSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// 绘制连线
|
// 绘制方形路径
|
||||||
g.DrawLine(pen, _lastDrawPoint, imagePoint);
|
int halfSize = _currentBrushSize / 2;
|
||||||
|
using (SolidBrush brush = new SolidBrush(selectedColor))
|
||||||
|
{
|
||||||
|
// 计算两点之间的直线区域,并绘制方形
|
||||||
|
DrawLineAsRectangles(g, brush, _lastDrawPoint, imagePoint, halfSize);
|
||||||
|
}
|
||||||
// 更新上一个点
|
// 更新上一个点
|
||||||
_lastDrawPoint = imagePoint;
|
_lastDrawPoint = imagePoint;
|
||||||
}
|
}
|
||||||
@@ -2882,9 +2929,9 @@ namespace JoyD.Windows.CS
|
|||||||
adjustedBrushSize = Math.Min(adjustedBrushSize, 50); // 最大50像素
|
adjustedBrushSize = Math.Min(adjustedBrushSize, 50); // 最大50像素
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制擦除区域(圆形)
|
// 绘制擦除区域(方形)
|
||||||
int radius = adjustedBrushSize / 2;
|
int halfSize = adjustedBrushSize / 2;
|
||||||
g.FillEllipse(Brushes.Transparent, imagePoint.X - radius, imagePoint.Y - radius, adjustedBrushSize, adjustedBrushSize);
|
g.FillRectangle(Brushes.Transparent, imagePoint.X - halfSize, imagePoint.Y - halfSize, adjustedBrushSize, adjustedBrushSize);
|
||||||
|
|
||||||
// 恢复CompositingMode为默认值
|
// 恢复CompositingMode为默认值
|
||||||
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
|
g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
|
||||||
@@ -2927,11 +2974,11 @@ namespace JoyD.Windows.CS
|
|||||||
adjustedBrushSize = Math.Min(adjustedBrushSize, 50); // 最大50像素
|
adjustedBrushSize = Math.Min(adjustedBrushSize, 50); // 最大50像素
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绘制区域(圆形)
|
// 绘制区域(方形)
|
||||||
int radius = adjustedBrushSize / 2;
|
int halfSize = adjustedBrushSize / 2;
|
||||||
using (SolidBrush brush = new SolidBrush(selectedColor))
|
using (SolidBrush brush = new SolidBrush(selectedColor))
|
||||||
{
|
{
|
||||||
g.FillEllipse(brush, imagePoint.X - radius, imagePoint.Y - radius, adjustedBrushSize, adjustedBrushSize);
|
g.FillRectangle(brush, imagePoint.X - halfSize, imagePoint.Y - halfSize, adjustedBrushSize, adjustedBrushSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user