优化结构
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Serilog;
|
||||
using XP.ImageProcessing.Processors;
|
||||
@@ -16,7 +17,7 @@ namespace XplorePlane.Services.ImageProcessing
|
||||
/// <summary>
|
||||
/// 对图像中的指定搜索范围执行边缘线拟合。
|
||||
/// </summary>
|
||||
public EdgeLineFitResult? ProcessImage(
|
||||
public XP.ImageProcessing.Processors.LineFitResult? ProcessImage(
|
||||
BitmapSource imageSource,
|
||||
int startX, int startY,
|
||||
int endX, int endY)
|
||||
|
||||
@@ -16,8 +16,8 @@ namespace XplorePlane.Services.ImageProcessing
|
||||
/// <param name="startY">搜索起始 Y</param>
|
||||
/// <param name="endX">搜索结束 X</param>
|
||||
/// <param name="endY">搜索结束 Y</param>
|
||||
/// <returns>拟合结果,包含输出数据字典</returns>
|
||||
EdgeLineFitResult ProcessImage(
|
||||
/// <returns>拟合结果,若失败则返回 null</returns>
|
||||
XP.ImageProcessing.Processors.LineFitResult? ProcessImage(
|
||||
BitmapSource imageSource,
|
||||
int startX, int startY,
|
||||
int endX, int endY);
|
||||
|
||||
@@ -19,5 +19,11 @@ namespace XplorePlane.Services.ImageProcessing
|
||||
|
||||
/// <summary>将 BitmapSource 保存到指定路径</summary>
|
||||
void SaveToFile(BitmapSource bitmap, string filePath, BitmapEncoder encoder);
|
||||
|
||||
/// <summary>将 BitmapSource 以 Gray16 TIFF 格式保存到文件</summary>
|
||||
void SaveAsGray16Tiff(BitmapSource bitmap, string filePath);
|
||||
|
||||
/// <summary>根据文件扩展名自动选择编码器保存图像</summary>
|
||||
void SaveWithFormat(BitmapSource bitmap, string filePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Serilog;
|
||||
using XplorePlane.ViewModels.ImageProcessing;
|
||||
|
||||
@@ -21,6 +21,7 @@ using XplorePlane.Services;
|
||||
using XplorePlane.Services.Inspection;
|
||||
using XplorePlane.Services.Main.Viewport;
|
||||
using XplorePlane.ViewModels;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace XplorePlane.Views.Main
|
||||
{
|
||||
@@ -1755,7 +1756,7 @@ namespace XplorePlane.Views.Main
|
||||
};
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
|
||||
var ext = Path.GetExtension(dialog.FileName).ToLower();
|
||||
var ext = System.IO.Path.GetExtension(dialog.FileName).ToLower();
|
||||
if (ext == ".tif" || ext == ".tiff")
|
||||
{
|
||||
// TIFF 直接走服务保存
|
||||
@@ -1801,7 +1802,7 @@ namespace XplorePlane.Views.Main
|
||||
};
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
|
||||
var ext = Path.GetExtension(dialog.FileName).ToLower();
|
||||
var ext = System.IO.Path.GetExtension(dialog.FileName).ToLower();
|
||||
var encoder = ImageSaveService.CreateEncoder(ext);
|
||||
ImageSaveService.SaveToFile(bitmap, dialog.FileName, encoder);
|
||||
|
||||
@@ -2187,7 +2188,7 @@ namespace XplorePlane.Views.Main
|
||||
|
||||
#endregion
|
||||
|
||||
#region 边缘查找拟合直线
|
||||
#region 边缘查找拟合直线
|
||||
|
||||
private void ExecuteEdgeLineFitProcessor(Point startPoint, Point endPoint)
|
||||
{
|
||||
@@ -2300,7 +2301,29 @@ namespace XplorePlane.Views.Main
|
||||
Canvas.SetLeft(label, labelX);
|
||||
Canvas.SetTop(label, labelY);
|
||||
canvas.Children.Add(label);
|
||||
canvas.Children.Add(label);
|
||||
_elfOverlays.Add(label);
|
||||
}
|
||||
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 按名称查找可视化子元素
|
||||
/// </summary>
|
||||
private static T? FindChildByName<T>(DependencyObject parent, string childName) where T : DependencyObject
|
||||
{
|
||||
if (parent == null) return null;
|
||||
|
||||
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(parent); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(parent, i);
|
||||
if (child is FrameworkElement fe && fe.Name == childName && child is T t)
|
||||
return t;
|
||||
|
||||
var found = FindChildByName<T>(child, childName);
|
||||
if (found != null) return found;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user