来自 OxyPlot Documentation Website 上的文档,它说要使用 PngExporter
类。 OxyPlot 中不再存在此类,而是存在名为 PngEncoder
和 PngDecoder
的类。我怀疑与 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/