I’m trying to make sure I can get the full extents of the image before converting to something is useful for inclusion in a report; however, when I run the following code the image is not showing the entire zoomed out chart. The chart is however zoomed out when this function is complete.
Dispatcher.Invoke(() => CrosslineGraph.DoseChart.ZoomExtents());
BitmapSource bitmap = CrosslineGraph.DoseChart.ExportToBitmapSource();
byte[] bytes;
using (MemoryStream stream = new MemoryStream())
{
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
encoder.Save(stream);
bytes = stream.ToArray();
}
- Chris Kirkman asked 5 years ago
- You must login to post comments
Because you’re exporting you will need to set SciChartSurface.RenderPriority=Immediate when changing your properties so that the chart will draw immediately, before export.
I would suggest something like this
try
{
sciChartSurface.RenderPriority = RenderPriority.Immediate;
sciChartSurface.ZoomExtents();
var bitmap = sciChartSurface.ExportToBitmapSource();
}
finally
{
sciChartSurface.RenderPriority = RenderPriority.Normal;
}
Be advised, RenderPriority.Immediate means ‘redraw on anything changed, properties, styles, data’ and will make your application extremely slow if you forget to set it back to Normal.
- Andrew Burnett-Thompson answered 5 years ago
-
I have more than one chart in my UI, and they are on separate tabs. As soon as I call .ExportToBitmapSource() for one of the charts that is not shown (it’s tab is not selected) an exception is thrown… UIElement.Measure(availableSize) cannot be called with NaN size. Is there a way around this?
- You must login to post comments
Please login first to submit.