diff --git a/Source/QuestPDF/Drawing/ImageCanvas.cs b/Source/QuestPDF/Drawing/ImageCanvas.cs index ac0b68b..657ee06 100644 --- a/Source/QuestPDF/Drawing/ImageCanvas.cs +++ b/Source/QuestPDF/Drawing/ImageCanvas.cs @@ -42,7 +42,7 @@ namespace QuestPDF.Drawing public override void EndPage() { Canvas.Save(); - var image = Surface.Snapshot().Encode(Settings.Format, Settings.Quality).ToArray(); + var image = Surface.Snapshot().Encode(Settings.ImageFormat.ToSkImageFormat(), Settings.ImageCompressionQuality.ToQualityValue()).ToArray(); Images.Add(image); Canvas.Dispose(); diff --git a/Source/QuestPDF/Helpers/Helpers.cs b/Source/QuestPDF/Helpers/Helpers.cs index 30762b3..67b624b 100644 --- a/Source/QuestPDF/Helpers/Helpers.cs +++ b/Source/QuestPDF/Helpers/Helpers.cs @@ -62,6 +62,17 @@ namespace QuestPDF.Helpers return size.Width < 0f || size.Height < 0f; } + internal static SKEncodedImageFormat ToSkImageFormat(this ImageFormat format) + { + return format switch + { + ImageFormat.Jpeg => SKEncodedImageFormat.Jpeg, + ImageFormat.Png => SKEncodedImageFormat.Png, + ImageFormat.Webp=> SKEncodedImageFormat.Webp, + _ => throw new ArgumentOutOfRangeException(nameof(format), format, null) + }; + } + internal static int ToQualityValue(this ImageCompressionQuality quality) { return quality switch diff --git a/Source/QuestPDF/Infrastructure/ImageFormat.cs b/Source/QuestPDF/Infrastructure/ImageFormat.cs new file mode 100644 index 0000000..78b9a14 --- /dev/null +++ b/Source/QuestPDF/Infrastructure/ImageFormat.cs @@ -0,0 +1,9 @@ +namespace QuestPDF.Infrastructure +{ + public enum ImageFormat + { + Jpeg, + Png, + Webp + } +} \ No newline at end of file diff --git a/Source/QuestPDF/Infrastructure/ImageGenerationSettings.cs b/Source/QuestPDF/Infrastructure/ImageGenerationSettings.cs index 29be37d..eafd8b5 100644 --- a/Source/QuestPDF/Infrastructure/ImageGenerationSettings.cs +++ b/Source/QuestPDF/Infrastructure/ImageGenerationSettings.cs @@ -7,20 +7,19 @@ namespace QuestPDF.Infrastructure /// /// The file format used to encode the image(s). /// - public SKEncodedImageFormat Format { get; set; } = SKEncodedImageFormat.Png; + public ImageFormat ImageFormat { get; set; } = ImageFormat.Png; /// - /// The quality level to use for the image(s). This is in the range from 0-100. + /// Encoding quality controls the trade-off between size and quality. + /// The default value is "high quality". /// - public int Quality { get; set; } = 100; + public ImageCompressionQuality ImageCompressionQuality { get; set; } = ImageCompressionQuality.VeryHigh; /// - /// The DPI (pixels-per-inch) at which images and features without native PDF support will be rasterized. - /// A larger DPI would create a PDF that reflects the original intent with better fidelity, but it can make for larger PDF files too, which would use more memory while rendering, and it would be slower to be processed or sent online or to printer. - /// When generating images, this parameter also controls the resolution of the generated content. + /// The DPI (pixels-per-inch) at which the document will be rasterized. This parameter controls the resolution of produced images. /// Default value is 144. /// - public int RasterDpi { get; set; } = 144; + public int RasterDpi { get; set; } = DocumentSettings.DefaultRasterDpi * 2; public static ImageGenerationSettings Default => new ImageGenerationSettings();