I need to save and print an image from cartesian live chart, I've searched in docs and tutorials but I can't find anything. How can I do this? I'm using WinForms and C# with Visual Studio 2012 Express.
As it seems that the graph itself does not support printing / taking screens to image, I would suggest creating this functionality Yourself.
What are You going to need?
-
ScreenCapture sc = new ScreenCapture();
// capture entire screen, and save it to a file
Image img = sc.CaptureScreen();
// display image in a Picture control named imageDisplay
this.imageDisplay.Image = img;
// capture this window, and save it
sc.CaptureWindowToFile(this.Handle,"C:\\temp2.gif",ImageFormat.Gif);
In case You need just printscreen of control: C# Take ScreenShot of .net control within application and attach to Outlook Email
-
public static void TakeCroppedScreenShot( string fileName, int x, int y, int width, int height, ImageFormat format)
{
Rectangle r = new Rectangle(x, y, width, height);
Bitmap bmp = new Bitmap(r.Width, r.Height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(r.Left, r.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
bmp.Save(fileName, format);
}
-
using System.Drawing.Printing;
...
protected void btnPrint_Click(object sender, EventArgs e)
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += PrintPage;
pd.Print();
}
private void PrintPage(object o, PrintPageEventArgs e)
{
System.Drawing.Image img = System.Drawing.Image.FromFile("D:\\Foto.jpg");
Point loc = new Point(100, 100);
e.Graphics.DrawImage(img, loc);
}