I am trying to take screenshot of the chart when I click a button and save it. when I click the same button I want it to take fresh new screenshot and replace the previous screenshot file which saved. At the moment my code is like below:
private void OnScreenShotButtonClick(object sender, RoutedEventArgs rea)
{
System.Windows.Controls.Button button = sender as System.Windows.Controls.Button;
if (button != null)
Dispatcher.BeginInvoke(new Action(() =>
{
if (chart != null && takeShot == true)
{
RenderTargetBitmap screenCapture = chart.GetScreenshot(ShareScreenshotType.Chart);
outputFrame = BitmapFrame.Create(screenCapture);
if (screenCapture != null)
{
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(outputFrame);
using (Stream stream = File.Create(string.Format(@"{0}\{1}", Core.Globals.UserDataDir, "MyScreenshot.png")))
png.Save(stream);
Print("Screenshot saved to " + Core.Globals.UserDataDir);
takeShot = false;
}
}
}));
}
I have taken this code from a support forum post https://ninjatrader.com/support/foru...re?postcount=7 and found the sample called MyscreenTaker.cs
my code above takes screenshot once, then if I click, it does not work or replace. I will appreciate if anyone can guide me to the right direction please. I am definitely doing something wrong here.
Thanks in advance.
Comment