如何在 UWP 中将 Oxyplot 导出为 PNG?

How to export Oxyplot to PNG in UWP?

我正在为 UWP 使用 Oxyplot,并希望将我的绘图导出为 png。可以在 UWP 中导出为 PDF,但我想知道是否可以解决导出为 PNG 的问题。我知道在 WPF 中可以导出到 PNG,但 UWP 中的 PngExporter 还不支持这样:

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

这是他们的文档中包含的部分:

当尝试在 UWP 上安装这些库中的任何一个时,它会导致应用程序出现预期的错误和功能问题。

对于 UWP 的这个 PNG 问题,是否有任何解决方法?或者 PDF 是我唯一可用的导出选项吗?可以导出为 PDF,然后将 PDF 转换为 PNG 吗?感谢您提供解决方法的帮助!

How to export Oxyplot to PNG in UWP?

目前Oxyplot还没有提供UWP平台内PDF转PNG的功能。但是,您可以使用 PDFTron. And this code sample 将 PDF 转换为 png。要将 pdf 转换为 png,请检查 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));
}