[英]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.