Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Taking screenshot programmatically
Collapse
X
-
Taking screenshot programmatically
Are there any prewritten methods to take a chart screenshot programmatically? I developed a jpg graphic that plots statistical distributions, but I need to view what the chart was doing at the time for it to make any sense.Tags: None
-
-
It's actually pretty easy. Use "ChartControl" in lieu of "chart and it works fine.
Code:System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(chart.ChartPanel.Width, chart.ChartPanel.Height, PixelFormat.Format16bppRgb555); chart.ChartPanel.DrawToBitmap(bmp, chart.ChartPanel.ClientRectangle);
Comment
-
Originally posted by texasnomad View PostThe ChartPanel only updates in a strategy and not in an indicator, per this post. Does anyone have a suggestion of how to make it update in an indicator?
http://www.ninjatrader.com/support/f...ght=ChartPanel
I have found that when I try to capture any of the ChartPanel, the Parent, or the ParentForm, regardless, I get an empty window showing the Panel but no candles, or any other content drawn.
Maybe they changed something in 7.x, in the way that they construct the chart? It is strange though, because even if I change the code to capture the entire screen instead of just the NT chart, it captures the screen, with all windows showing their uncovered content, except for the NT chart, which still shows up as a blank palette. Hm.
Then again, all the ChartControl functions are unsupported, so there is nothing to cavil about.
Comment
-
No, it actually seems to be wrong. I took the post's word for it. When I tried it, I keep running into the same problems.
Comment
-
I tried using the chart's Paint and AfterPaint events to get the graphic and draw it to a bmp. I still can't get it working.
using System.Drawing.Imaging;
using System.Windows.Forms;
Code:#region Variables private Bitmap bmp; #endregion protected override void OnStartUp() { ChartControl.Paint += new PaintEventHandler(OnChartPaint); bmp = new Bitmap(800,600); } protected void OnChartPaint(object sender, PaintEventArgs e) { e.Graphics.DrawImageUnscaled(bmp,0,0); bmp.Save(@"C:\testImage.jpg",ImageFormat.Jpeg); } protected void OnTermination() { ChartControl.Paint -= new PaintEventHandler(OnChartPaint); }
Last edited by texasnomad; 01-03-2012, 05:07 PM.
Comment
-
Originally posted by texasnomad View PostI tried using the chart's Paint and AfterPaint events to get the graphic and draw it to a bmp. I still can't get it working.
using System.Drawing.Imaging;
using System.Windows.Forms;
Code:#region Variables private Bitmap bmp; #endregion protected override void OnStartUp() { ChartControl.Paint += new PaintEventHandler(OnChartPaint); bmp = new Bitmap(800,600); } protected void OnChartPaint(object sender, PaintEventArgs e) { e.Graphics.DrawImageUnscaled(bmp,0,0); bmp.Save(@"C:\testImage.jpg",ImageFormat.Jpeg); } protected void OnTermination() { ChartControl.Paint -= new PaintEventHandler(OnChartPaint); }
Comment
-
I had the same happening to me. I'm currently using the following to save my chart.
#region Global Variables
public string DefaultFileLocation = Environment.GetFolderPath(Environment.SpecialFolde r.MyDocuments) + "\\NinjaTrader 7\\charts\\";
#endregion
#region fnSaveChart
[Description("Saving the active chart to a file")]
public void fnSaveChart (ChartControl chart, string Description, string Location)
{
if ( Historical ) return;
if ( Location == "<default>" ) Location = DefaultFileLocation;
string tFileName = Location
+ Description + " "
+ Instrument.FullName.ToString() + " "
+ "(" + BarsPeriod.Value + " " + BarsPeriod.Id + ") "
+ Time[0].Year.ToString() + "-"
+ Time[0].Month.ToString("00") + "-"
+ Time[0].Day.ToString("00") + " "
+ Time[0].Hour.ToString("00") + "."
+ Time[0].Minute.ToString("00") + "."
+ Time[0].Second.ToString("00") + "."
+ "jpg";
if (chart.ParentForm.WindowState == FormWindowState.Minimized)
{
Print("[fnSaveChart]Chart form window state must be maximized or normal to capture. Chart not saved.");
return;
}
try
{
// create the bitmap (empty)
Bitmap bitmap = new System.Drawing.Bitmap(chart.ChartPanel.Width, chart.ChartPanel.Height, PixelFormat.Format16bppRgb555);
// get bitmap of chart panel
chart.ChartPanel.DrawToBitmap(bitmap, chart.ChartPanel.ClientRectangle);
bitmap.Save( tFileName, ImageFormat.Jpeg );
}
catch (Exception ex)
{
Print ("[fnSaveChart] Exception: " + ex);
}
return;
}
#endregion
The function is called via
fnSaveChart (ChartControl, "End Trade", @"<default>");Last edited by Hans B; 01-04-2012, 07:45 AM.
Comment
-
And when you do that, what does testImage.jpg look like?Last edited by texasnomad; 01-04-2012, 02:13 PM.
Comment
-
This is the part that I believe that I left out. I'll have to check on it when I get more time.
Code:chart.ChartPanel.DrawToBitmap(bitmap, chart.ChartPanel.ClientRectangle);
Comment
-
Sometimes I also use this one. Rather than saving the active chart, it saves the screen (or all of them if you have mutliple).
try
{
int Screens = Screen.AllScreens.Length; // dell8300 2 screen, laptop 1 screen
Bitmap bitmap = new Bitmap(Screens * Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); // adjusted for dual screens
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
bitmap.Save(tFileName, ImageFormat.Jpeg);
}
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Lele2k24, Yesterday, 11:24 AM
|
12 responses
36 views
0 likes
|
Last Post Today, 03:07 PM | ||
Started by RaygunWizzle, Yesterday, 08:52 PM
|
3 responses
11 views
0 likes
|
Last Post Today, 02:50 PM | ||
Started by Tim-c, Today, 08:36 AM
|
4 responses
14 views
0 likes
|
Last Post Today, 02:45 PM | ||
Started by JohnS52, 03-22-2024, 08:06 AM
|
4 responses
28 views
0 likes
|
Last Post
by JohnS52
Today, 02:30 PM
|
||
Started by carnitron, 03-25-2024, 01:59 PM
|
11 responses
53 views
0 likes
|
Last Post
by carnitron
Today, 02:18 PM
|
Comment