TURBO-569:更新工程结构;将导航相机标定和校准功能迁移到XP.Camera类

This commit is contained in:
李伟
2026-04-20 16:09:17 +08:00
parent e166eca3d7
commit 9218384e3f
24 changed files with 2429 additions and 124 deletions
+34
View File
@@ -0,0 +1,34 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace XP.Camera;
/// <summary>
/// 提供像素数据到 WPF BitmapSource 的转换工具方法。
/// </summary>
public static class PixelConverter
{
/// <summary>
/// 将原始像素数据转换为 WPF 的 BitmapSource 对象。
/// 返回的 BitmapSource 已调用 Freeze(),可跨线程访问。
/// </summary>
public static BitmapSource ToBitmapSource(byte[] pixelData, int width, int height, string pixelFormat)
{
ArgumentNullException.ThrowIfNull(pixelData);
if (width <= 0) throw new ArgumentException("Width must be a positive integer.", nameof(width));
if (height <= 0) throw new ArgumentException("Height must be a positive integer.", nameof(height));
ArgumentNullException.ThrowIfNull(pixelFormat);
var (format, stride) = pixelFormat switch
{
"Mono8" => (PixelFormats.Gray8, width),
"BGR8" => (PixelFormats.Bgr24, width * 3),
"BGRA8" => (PixelFormats.Bgra32, width * 4),
_ => throw new NotSupportedException($"Pixel format '{pixelFormat}' is not supported.")
};
var bitmap = BitmapSource.Create(width, height, 96, 96, format, null, pixelData, stride);
bitmap.Freeze();
return bitmap;
}
}