[英]Using OxyPlot to render png images from a PlotModel
从OxyPlot文档网站上的文档中 ,它说使用PngExporter
类。 OxyPlot中不再存在此类,而是存在名为PngEncoder
和PngDecoder
类。 我怀疑PngExporter.Export
的等效方法是PngEncoder.Encode
但是它要求一个名为“pixels”的2d OxyColor
数组,但我不知道从哪里获取这些数据。 注意:导出到SVG或PDF工作,但此表单是无用的。
问题:我需要从PlotModel
中的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。
使用[GitHub Oxyplot]文件构建图书馆,包括oxyplot和oxyplot.wpf,然后使用这些库代替。 请注意,导出PNG的任何方法都必须具有STAThread标记。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.