1- using SixLabors . ImageSharp ;
1+ using DotNetCampus . MediaConverters . Imaging . Effect . Colors ;
2+ using DotNetCampus . MediaConverters . Imaging . Effect . Extensions ;
3+
4+ using SixLabors . ImageSharp ;
5+ using SixLabors . ImageSharp . Advanced ;
26using SixLabors . ImageSharp . PixelFormats ;
37
48using System ;
59using System . Collections . Generic ;
610using System . Linq ;
711using System . Threading . Tasks ;
8- using DotNetCampus . MediaConverters . Imaging . Effect . Colors ;
9- using DotNetCampus . MediaConverters . Imaging . Effect . Extensions ;
10- using SixLabors . ImageSharp . Advanced ;
12+
13+ using static System . Net . Mime . MediaTypeNames ;
1114
1215namespace DotNetCampus . MediaConverters . Imaging . Effect ;
1316
@@ -185,6 +188,18 @@ public static void SetSoftEdgeEffect(this Image<Rgba32> bitmap, float radius)
185188 /// </summary>
186189 /// <param name="image"></param>
187190 public static ColorCount GetMaxCountColor ( this Image < Rgba32 > image )
191+ {
192+ var list = image . GetColorCount ( ) ;
193+
194+ return list . MaxBy ( t => t . Count ) ;
195+ }
196+
197+ /// <summary>
198+ /// 获取无序的颜色数量列表
199+ /// </summary>
200+ /// <param name="image"></param>
201+ /// <returns></returns>
202+ public static IReadOnlyList < ColorCount > GetColorCount ( this Image < Rgba32 > image )
188203 {
189204 var dictionary = new Dictionary < Rgba32 , int > ( ) ;
190205 image . ProcessPixelRows ( accessor =>
@@ -206,8 +221,7 @@ public static ColorCount GetMaxCountColor(this Image<Rgba32> image)
206221 }
207222 } ) ;
208223
209- var ( color , count ) = dictionary . MaxBy ( pair => pair . Value ) ;
210- return new ColorCount ( color , count ) ;
224+ return [ ..dictionary . Select ( t => new ColorCount ( t . Key , t . Value ) ) ] ;
211225 }
212226}
213227
0 commit comments