简体   繁体   中英

How to export Oxyplot to PNG in UWP?

I am using Oxyplot for UWP and would like to export my plot to a png. It is possible to export to PDF in UWP but I was wondering if there was a work around for exporting to PNG. I know exporting to PNG is possible in WPF but not yet supported with the PngExporter in UWP like so:

using (var stream = File.Create(ApplicationData.Current.LocalFolder.Path + "\\" + "test.png"))
{
    var pngExporter = new PngExporter { Width = 800, Height = 400 };
    pngExporter.Export(PluggingPlot, stream);
}

This is the section included in their documentation document: 文档图片

When trying to install either of those libraries on UWP it causes errors and functionality issues of the application as to be expected.

Is there any sort of work around for this PNG issue for UWP? Or is PDF the only exporting option available to me? Possible to export to PDF then convert PDF to PNG maybe? Thanks for any help on a work-around!

How to export Oxyplot to PNG in UWP?

Currently, Oxyplot has not provided to convert PDF to PNG within UWP platform. However, you could convert PDF to png with PDFTron . And this code sample . For converting pdf to png please check PDFDraw class.

try
{
    // A) Open the PDF document.
    using (PDFDoc doc = new PDFDoc(Path.Combine(InputPath, "tiger.pdf")))
    {
        // Initialize the security handler, in case the PDF is encrypted.
        doc.InitSecurityHandler();

        // B) The output resolution is set to 92 DPI.
        draw.SetDPI(92);

        // C) Rasterize the first page in the document and save the result as PNG.
        pdftron.PDF.Page pg = doc.GetPage(1);
        String output_file_path = Path.Combine(OutputPath, "tiger_92dpi.png");
        draw.Export(pg, output_file_path);
        WriteLine(String.Format("Example 1: Result saved in {0}", output_file_path));
        await AddFileToOutputList(output_file_path).ConfigureAwait(false);

        // Export the same page as TIFF
        output_file_path = Path.Combine(OutputPath, "tiger_92dpi.tif");
        draw.Export(pg, output_file_path, "TIFF");
        await AddFileToOutputList(output_file_path).ConfigureAwait(false);
    }
}
catch (Exception e)
{
    WriteLine(GetExceptionMessage(e));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM