internal static void ExportSkp(IToolContext context, string path, IContainerView containerView) { var recorder = new SKPictureRecorder(); var rect = new SKRect(0f, 0f, (float)containerView.Width, (float)containerView.Height); var canvas = recorder.BeginRecording(rect); using (var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView)) { skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0); } var picture = recorder.EndRecording(); var dimensions = new SKSizeI((int)containerView.Width, (int)containerView.Height); using (var image = SKImage.FromPicture(picture, dimensions)) { var data = image.EncodedData; if (data != null) { using (var stream = File.OpenWrite(path)) { data.SaveTo(stream); } } } picture.Dispose(); }
public string ConvertToSvgDocument(IToolContext context, IContainerView containerView) { using (var stream = new MemoryStream()) { using (var wstream = new SKManagedWStream(stream)) using (var writer = new SKXmlStreamWriter(wstream)) using (var canvas = SKSvgCanvas.Create(SKRect.Create(0, 0, (int)containerView.Width, (int)containerView.Height), writer)) { if (containerView.SelectionState?.Shapes?.Count > 0) { using (var skiaSelectedPresenter = new SkiaExportSelectedPresenter(context, containerView)) { skiaSelectedPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0); } } else { using (var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView)) { skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0); } } } stream.Position = 0; using (var reader = new StreamReader(stream, Encoding.UTF8)) { var xml = reader.ReadToEnd(); return(FormatXml(xml)); } } }
internal static void ExportSvg(IToolContext context, string path, IContainerView containerView) { using var wstream = new SKFileWStream(path); using var canvas = SKSvgCanvas.Create(SKRect.Create(0, 0, (int)containerView.Width, (int)containerView.Height), wstream); using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView); skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0); }
internal static void ExportXps(IToolContext context, string path, IContainerView containerView) { using var stream = new SKFileWStream(path); using var xps = SKDocument.CreateXps(stream, SKDocument.DefaultRasterDpi); using var canvas = xps.BeginPage((float)containerView.Width, (float)containerView.Height); using var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView); skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0); xps.Close(); }
internal static void ExportPdf(IToolContext context, string path, IContainerView containerView) { using (var stream = new SKFileWStream(path)) using (var pdf = SKDocument.CreatePdf(stream, SKDocument.DefaultRasterDpi)) using (var canvas = pdf.BeginPage((float)containerView.Width, (float)containerView.Height)) using (var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView)) { skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0); pdf.Close(); } }
internal static void ExportImage(IToolContext context, string path, IContainerView containerView, SKEncodedImageFormat format, int quality) { var info = new SKImageInfo((int)containerView.Width, (int)containerView.Height, SKImageInfo.PlatformColorType, SKAlphaType.Unpremul); using var bitmap = new SKBitmap(info); using (var canvas = new SKCanvas(bitmap)) using (var skiaContainerPresenter = new SkiaExportContainerPresenter(context, containerView)) { skiaContainerPresenter.Draw(canvas, containerView.Width, containerView.Height, 0, 0, 1.0, 1.0); } using var image = SKImage.FromBitmap(bitmap); using var data = image.Encode(format, quality); if (data != null) { using var stream = File.OpenWrite(path); data.SaveTo(stream); } }