c# - 使用 OxyPlot 从 PlotModel 渲染 png 图像

标签 c# graph export png oxyplot

来自 OxyPlot Documentation Website 上的文档,它说要使用 PngExporter 类。 OxyPlot 中不再存在此类,而是存在名为 PngEncoderPngDecoder 的类。我怀疑与 PngExporter.Export 等效的方法是 PngEncoder.Encode 但是它要求 OxyColor 的二维数组称为“像素”,但我不知道从哪里得到这些数据。 注意:可以导出为 SVG 或 PDF,但这种形式没有用。

问题:我只需要从 OxyPlot 中的 PlotModel 代码导出 PNG,但文档已过时。

这是我被告知要使用的代码:

 using (var stream = File.Create(fileName))
    {
        var pngExporter = new PngExporter();
        pngExporter.Export(plotModel, stream, 600, 400, Brushes.White);
    }

最佳答案

要添加到 Jamie 的答案中,如果您想从类库中导出 png,您可以使用 STAThread 执行类似的操作:

        var thread = new Thread(() =>
        {
            PngExporter.Export(plotModel, @"C:\file.png", 600, 400, OxyColors.White);
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();
        thread.Join();

这是使用最新的预发布 v1.0.0-unstable2100。

关于c# - 使用 OxyPlot 从 PlotModel 渲染 png 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34003745/

相关文章:

c# - 为什么 C# 不允许像 C++ 这样的非成员函数

c# - 自承载 WCF 服务中的 HTTP 413 请求实体太大

python - 如何在 scipy 中读取稀疏有向图

cocoa - 使用 xCode 制作图表

php - 使用 PHP/Joomla 以编程方式将 MySql 数据库导出到 CSV

mysql - 将 MySQL 查询结果以 CSV 文件导出到我的 PC

c# - 捕获用户控件中的所有鼠标事件

python - 如何在 Django 网页中嵌入 matplotlib 图形?

asp.net - 我可以通过 Visual Studio 从 ASP.NET 网站导出生成的 html 页面吗?

c# - 带参数运行EXE