Save Plot to image

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

tboloo wrote at 2013-10-09 15:16:

Hi everyone,
I am trying to create a report which is supposed to include plot graphics and data (from other views in the application). Now I have checked the documentation and forums, and it seems that there is no ToImage() method in OxyPlot.WPF, neither there are SaveBitmap, ToBitmap methods mentioned in elswwhere, only ToCode and ToSVG which are of no use in my scenario. So my question is is there a simple, or relatively simple, way to get the plot as image?
Regards,
Bolek.

willmoore88 wrote at 2013-10-10 12:36:

You can simply do a CTRL+C to copy the plot to the clipboard? Might point you in the right direction.

tboloo wrote at 2013-10-10 13:39:

CTRL+C works, but what I need is to call it from my ViewModel, but I can not call
System.Windows.Input.ApplicationCommands.Copy.Execute(null, PlotModel);  
as PlotModel is not of IInputElement type.

Gimly wrote at 2013-10-11 17:04:

Why don't you use the PngExporter?
Usage example:
PngExporter.Export(this.PlotModel, stream, 800, 600);
That creates the image in the form of a PNG in the stream (for example a filestream or a memory stream.

You can also use
BitmapSource bitmap = PngExporter.ExportToBitmap(this.PlotModel, width, height, backgroundColor);
This create a BitmapSource that can easily be added to the clipboard or used any way you want.

Hope this helps.

tboloo wrote at 2013-10-14 12:20:

Thanks Gimly, tthat solves my issues.
Regards,
Bolek.