[C#]
//Draw chart in an Image or Bitmap object
Image img = new Bitmap(this.chartControl1.Width, this.chartControl1.Height);
this.chartControl1.Draw(img);
//Convert image to stream
Stream stream = new MemoryStream();
img.Save(stream, ImageFormat.Png);
//Convert stream to bytes
byte[] chartBytes = new byte[stream.Length];
stream.Write(chartBytes, 0, chartBytes.Length);
//For verifying the exported image.
img.Save("Chart.png");
//Dispose image and stream
img.Dispose();
stream.Dispose();
|
[C#]
//Draw chart in an Image or Bitmap object
Image img = new Bitmap(this.chartControl1.Width, this.chartControl1.Height);
this.chartControl1.Draw(img);
//Convert image to memory stream
MemoryStream stream = new MemoryStream();
img.Save(stream, ImageFormat.Png);
//Convert memory stream to bytes
byte[] chartBytes = stream.ToArray();
//For verifying the exported image.
stream.Dispose();
img.Dispose();
stream = new MemoryStream(chartBytes);
img = Image.FromStream(stream);
img.Save("Chart.png");
//Dispose image and stream
img.Dispose();
stream.Dispose();
|