using SixLabors.ImageSharp.PixelFormats; namespace Masuit.Tools.Media; /// /// 边框检测结果(包含多层边框信息) /// public struct BorderDetectionResult { private int CroppedBorderCount { get; set; } public BorderDetectionResult(int croppedBorderCount) { CroppedBorderCount = croppedBorderCount; } /// 原始图片宽度 public int ImageWidth { get; set; } /// 原始图片高度 public int ImageHeight { get; set; } /// 内容上边界位置 public int ContentTop { get; set; } /// 内容下边界位置 public int ContentBottom { get; set; } /// 内容左边界位置 public int ContentLeft { get; set; } /// 内容右边界位置 public int ContentRight { get; set; } /// 检测到的边框层数 public int BorderLayers { get; set; } /// 边框颜色层次(从外到内) public List BorderColors { get; set; } /// 顶部边框总宽度(像素) public int TopBorderWidth => ContentTop; /// 底部边框总宽度(像素) public int BottomBorderWidth => ImageHeight - 1 - ContentBottom; /// 左侧边框总宽度(像素) public int LeftBorderWidth => ContentLeft; /// 右侧边框总宽度(像素) public int RightBorderWidth => ImageWidth - 1 - ContentRight; /// 是否有顶部边框 public bool HasTopBorder => TopBorderWidth > 0; /// 是否有底部边框 public bool HasBottomBorder => BottomBorderWidth > 0; /// 是否有左侧边框 public bool HasLeftBorder => LeftBorderWidth > 0; /// 是否有右侧边框 public bool HasRightBorder => RightBorderWidth > 0; /// 是否有任意边框 public bool HasAnyBorder => BorderCount > 0; /// 是否满足裁剪条件(至少两个边) public bool CanBeCropped => BorderCount >= CroppedBorderCount; public int BorderCount => (HasTopBorder ? 1 : 0) + (HasBottomBorder ? 1 : 0) + (HasLeftBorder ? 1 : 0) + (HasRightBorder ? 1 : 0); /// 内容区域宽度 public int ContentWidth => ContentRight - ContentLeft + 1; /// 内容区域高度 public int ContentHeight => ContentBottom - ContentTop + 1; }