/// <inheritdoc/> public void Export(IPlotModel model, Stream stream) { using var bitmap = new SKBitmap(this.Width, this.Height); using (var canvas = new SKCanvas(bitmap)) using (var context = new SkiaRenderContext { RenderTarget = RenderTarget.PixelGraphic, SkCanvas = canvas }) { canvas.Clear(SKColors.White); var dpiScale = this.Dpi / 96; context.DpiScale = dpiScale; model.Update(true); var backgroundColor = model.Background; // jpg doesn't support transparency if (!backgroundColor.IsVisible()) { backgroundColor = OxyColors.White; } canvas.Clear(backgroundColor.ToSKColor()); model.Render(context, new OxyRect(0, 0, this.Width / dpiScale, this.Height / dpiScale)); } using var skStream = new SKManagedWStream(stream); SKPixmap.Encode(skStream, bitmap, SKEncodedImageFormat.Jpeg, this.Quality); }
/// <inheritdoc/> public void Export(IPlotModel model, Stream stream) { using var document = SKDocument.CreatePdf(stream); using var pdfCanvas = document.BeginPage(this.Width, this.Height); using var context = new SkiaRenderContext { RenderTarget = RenderTarget.VectorGraphic, SkCanvas = pdfCanvas, UseTextShaping = this.UseTextShaping }; const float dpiScale = 72f / 96; context.DpiScale = dpiScale; model.Update(true); pdfCanvas.Clear(model.Background.ToSKColor()); model.Render(context, new OxyRect(0, 0, this.Width / dpiScale, this.Height / dpiScale)); }
/// <inheritdoc/> public void Export(IPlotModel model, Stream stream) { using var skStream = new SKManagedWStream(stream); using var writer = new SKXmlStreamWriter(skStream); using var canvas = SKSvgCanvas.Create(new SKRect(0, 0, this.Width, this.Height), writer); if (!model.Background.IsInvisible()) { canvas.Clear(model.Background.ToSKColor()); } // SVG export does not work with UseTextShaping=true. However SVG does text shaping by itself anyway, so we can just disable it using var context = new SkiaRenderContext { RenderTarget = RenderTarget.VectorGraphic, SkCanvas = canvas, UseTextShaping = false }; model.Update(true); model.Render(context, new OxyRect(0, 0, this.Width, this.Height)); }
/// <inheritdoc/> public void Export(IPlotModel model, Stream stream) { using var bitmap = new SKBitmap(this.Width, this.Height); using (var canvas = new SKCanvas(bitmap)) using (var context = new SkiaRenderContext { RenderTarget = RenderTarget.PixelGraphic, SkCanvas = canvas, UseTextShaping = this.UseTextShaping }) { var dpiScale = this.Dpi / 96; context.DpiScale = dpiScale; model.Update(true); canvas.Clear(model.Background.ToSKColor()); model.Render(context, new OxyRect(0, 0, this.Width / dpiScale, this.Height / dpiScale)); } using var skStream = new SKManagedWStream(stream); SKPixmap.Encode(skStream, bitmap, SKEncodedImageFormat.Png, 0); }