From the documentation on the OxyPlot Documentation Website , it says to use the PngExporter
class. This class no longer exists in OxyPlot, but rather there are classes called PngEncoder
and PngDecoder
. I suspect the equivalent method to PngExporter.Export
is PngEncoder.Encode
however it asks for a 2d array of OxyColor
called "pixels", but I do not know where to get this data from. NOTE: Exporting to SVG or PDF works but this form is useless.
Problem: I need to export PNGs from code only of a PlotModel
in OxyPlot but documentation is outdated.
This is the code I have been told to use:
using (var stream = File.Create(fileName))
{
var pngExporter = new PngExporter();
pngExporter.Export(plotModel, stream, 600, 400, Brushes.White);
}
To add to Jamie's answer, if you want to export a png from say a class library, you can do something like this with STAThread:
var thread = new Thread(() =>
{
PngExporter.Export(plotModel, @"C:\file.png", 600, 400, OxyColors.White);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
This is using the latest pre-release v1.0.0-unstable2100.
Using the [GitHub Oxyplot] files to build the librarys, both oxyplot and oxyplot.wpf , and then use these libraries instead. Note any method which exports a PNG must be have the STAThread tag.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.