I would like to call ThemeManager.SetTheme to change the theme, export an image to file, and then restore the original theme. How can I ensure that the new theme has been applied before calling ExportToFile?
is there a better way to capture a screenshot of a plot using a different theme?
Bill
- William Lear asked 8 years ago
- You must login to post comments
After some investigation we discovered that we were not able to reproduce this in any of our automation tests, however, we were able to reproduce it in-app by modifying the Export and Screenshot Options example.
Here is our modified code which reproduces the issue:
private void ExportToPng(object sender, RoutedEventArgs e)
{
var saveFileDialog = CreateFileDialog("PNG | *.png");
if (saveFileDialog.ShowDialog() == true)
{
ThemeManager.SetTheme(sciChart, "Oscilloscope");
sciChart.ExportToFile(saveFileDialog.FileName, ExportType.Png, false);
ThemeManager.SetTheme(sciChart, "SciChartv4Dark");
}
}
The above code exports with the default theme (Dark). It does not have time to switch the theme before export. This is most likely due to the Style bindings in our themes which have not evaluated at the point where the ExportToFile call is made.
We discovered as you have, that having this setting:
sciChart.ExportToFile(saveFileDialog.FileName, ExportType.Png, true);
Or this setting
sciChart.ExportToFile(saveFileDialog.FileName, ExportType.Png, false, new Size(sciChart.ActualWidth, sciChart.ActualHeight));
Resolves the issue. This is because the use of Size? parameter or bool useXamlRenderSurface internally forces SciChart to recreate itself in memory (a copy) for rendering off-screen.
We also found that waiting to export like this worked:
private void ExportToPng(object sender, RoutedEventArgs e)
{
var saveFileDialog = CreateFileDialog("PNG | *.png");
if (saveFileDialog.ShowDialog() == true)
{
ThemeManager.SetTheme(sciChart, "BrightSpark");
sciChart.Dispatcher.BeginInvoke(new Action(() =>
{
sciChart.ExportToFile(saveFileDialog.FileName, ExportType.Png, false);
ThemeManager.SetTheme(sciChart, "SciChartv4Dark");
}), DispatcherPriority.ApplicationIdle);
}
}
This forces the application to wait until all Databindings have resolved. You will momentarily see the theme flicker to BrightSpark theme before the export then back to SciChartv4Dark.
In short, I don’t think we can ‘fix’ this internally as forcing databindings to resolve is quite hacky but hopefully one of the above workarounds should suffice!
Best regards,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
- last edited 8 years ago
- You must login to post comments
Hi Bill,
We’re doing a lot of work on fixing issues in Export to Png / XPS (which relies on Cloning a chart in memory, which in turn relies on serialization of the chart).
Part of this is to create a suite of visual tests that instantiate a chart in memory, export it to bitmap or XPS, and assert the output images are the same (or within small tolerance) to an expected visual.
I just created a new test to try to assert theme changes apply and they do – at least in the test.
Can you do me a favour and try our latest nightly build (v4.2.0.8956) which has about a bazzillion bug fixes in Export to file? Does the error still occur? If so we will continue to try to reproduce.
Best regards,
Andrew
- Andrew Burnett-Thompson answered 8 years ago
- You must login to post comments
Andrew,
I will be able to test the latest build within a couple of days.
Just to make sure we are testing the same scenario, what I am seeing is:
ExportToFile() correctly reproduces whatever theme is currently being displayed on the screen.
The problem occurs when I call ThemeManager.SetTheme, then immediately call ExportToFile.
I suspect the issue is either because this code sequence is being executed in a click event handler for a context menu on the plot.
Or is it that SetTheme is being performed asynchronously and has not had time to complete before I call ExportToFile?
Bill
- William Lear answered 8 years ago
-
We’re doing the same in an automation test and its working in v4.2.0 (in QA now). If you find any problems (the build doesnt work) then please get in touch with code to reproduce and we will update our test cases. Thanks and regards, Andrew
- You must login to post comments
Build 4.2.0.8960 did not immediately fix the problem. However, I noticed your Export and Screenshot example used the version of ExportToFile() that specified an explicit size. I changed to the ExportToFile overload with the Size arg, and the new theme was rendered as desired. The new theme is NOT rendered when using the overload that does not specify Size.
- William Lear answered 8 years ago
-
Oh that is interesting. I believe its because the Size() arg requires creating a complete copy of the chart in memory before rendering, hence why it works. We will try to reproduce our side and include a test case. Meanwhile, as a workaround Im sure you could use Size() arg with already known chart width, height (use SciChartSurface.ActualWidth, ActualHeight) to force the correct operation!
-
Andrew, Yes, specifying the size is not a problem. I may even capitalize on that and give the user the option to select a size. Bill
- You must login to post comments
Andrew,
Thanks for your help. So far, it looks like specifying the size is working quite well for me.
Bill
- William Lear answered 8 years ago
- You must login to post comments
Please login first to submit.