Skip to content

Commit 7208ad9

Browse files
committed
允许配置压缩率用于提升转换速度
1 parent 524fe12 commit 7208ad9

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/MediaConverters/MediaConverters.Tool/Contexts/ImageConvertContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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>

src/MediaConverters/MediaConverters.Tool/Program.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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");

0 commit comments

Comments
 (0)