Saving Screenshots

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Saving Screenshots

Post by hallo888 » Wed Sep 10, 2014 9:36 am

Hi,

I saw in some other post that screenshot of charts can be saved using the following codes

Code: Select all

Bitmap bm = ChartTools.CaptureControlToBitmap(m_chart);
bm.Save("c:\\temp\\combined.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
However, it seems like the CaptureContolToBitmap() function only takes in winform lightning chart. Is that correct? Is there any workaround for capturing screenshots of WPF chart control?

Thanks for your help.

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Saving Screenshots

Post by ArctionPasi » Wed Sep 10, 2014 10:45 am

You can simply use chart.SaveToFile("picture.bmp");

Works in both WPF and Winforms.
LightningChart Support Team, PT

hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Re: Saving Screenshots

Post by hallo888 » Thu Sep 11, 2014 9:48 am

ArctionPasi wrote:You can simply use chart.SaveToFile("picture.bmp");

Works in both WPF and Winforms.
Hi Parsi,

Thanks for the code. It works. However i am encountering an issue. Just a little backgroud, my chart is declared in the xaml file and is not shown on application startup. User will have to explictly click on a button in order to show the chart. On application startup, when the chart is still hidden but with all the data for the chart initialised, i encounter an exception "Saving to file failed: Make sure you have defined a valid target path, with write permission".
However, saving of the screenshot succeeds if save it after showing the chart. Even if i were to hide the chart subsequently, i am also able to save the screenshot successfully.

May i know what is the problem with it? I have checked that the chart is not null and has been initialised with all the data on startup.

Please advise.

User avatar
ArctionPasi
Posts: 1367
Joined: Tue Mar 26, 2013 10:57 pm
Location: Finland
Contact:

Re: Saving Screenshots

Post by ArctionPasi » Thu Sep 11, 2014 12:19 pm

Hello,

The chart must have been appeared on the screen at least once, before calling SaveToFile method. Otherwise chart control doesn't get a window handle and Direct3D can't be instantiated.

We will improve the error message to give some hint regarding this scenario.
LightningChart Support Team, PT

hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Re: Saving Screenshots

Post by hallo888 » Fri Sep 12, 2014 12:54 am

Oh ok. Thanks for the reply.

Post Reply