File tree Expand file tree Collapse file tree
src/MediaConverters/MediaConverters.Tool Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,11 @@ public class ImageConvertContext
1111
1212 public bool ? UseAreaSizeLimit { get ; init ; }
1313
14+ /// <summary>
15+ /// 压缩 PNG 图片时使用的压缩等级,1-9,数值越大压缩率越高但速度越慢,默认值为 6。在 1-9 之外的值会被视为默认值。
16+ /// </summary>
17+ public int PngCompressionLevel { get ; init ; }
18+
1419 /// <summary>
1520 /// 是否先行拷贝新的文件,再进行处理,避免图片占用
1621 /// </summary>
Original file line number Diff line number Diff line change @@ -152,6 +152,11 @@ internal static async Task<ErrorCode> RunAsync(ConvertHandler convertHandler)
152152 {
153153 ColorType = PngColorType . RgbWithAlpha ,
154154 BitDepth = PngBitDepth . Bit8 ,
155+ // 压缩等级 1-9,数值越大压缩率越高但速度越慢,默认值为 6。在 1-9 范围外的值会被视为默认值
156+ CompressionLevel = imageConvertContext . PngCompressionLevel is >= 1 and <= 9
157+ ? ( PngCompressionLevel ) imageConvertContext . PngCompressionLevel
158+ // 范围外,使用默认值
159+ : PngCompressionLevel . DefaultCompression
155160 } ) ;
156161
157162 context . LogMessage ( $ "[Performance] SaveAsPngAsync cost { stepStopwatch . ElapsedMilliseconds } ms Total { totalStopwatch . ElapsedMilliseconds } ms") ;
You can’t perform that action at this time.
0 commit comments