4

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);
    }
SharpC
  • 6,974
  • 4
  • 45
  • 40
Jamie Mair
  • 306
  • 3
  • 12
  • It says in the documentation "The PNG exporters are implemented in the platform specific libraries (OxyPlot.Wpf, OxyPlot.WindowsForms" - have you loaded one of these? – stuartd Nov 30 '15 at 17:02
  • 1
    Using the GitHub version of the project allowed me to get the PngExporter class in OxyPlot.Wpf, ran into a few more problems but eventually it has worked. Thanks for reply. – Jamie Mair Nov 30 '15 at 19:09

2 Answers2

4

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.

James Blake
  • 1,050
  • 1
  • 14
  • 17
1

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.

Jamie Mair
  • 306
  • 3
  • 12