2D Chart for WinForms | ComponentOne
Loading and Saving Charts, Data, and Images / Saving Chart Images
In This Topic
    Saving Chart Images
    In This Topic

    The C1Chart provides the ability to create a single image of the entire chart as it is drawn on the screen or printer. By calling the SaveImage method, all of the items within the chart bounds can be saved to the clipboard, a byte array, a stream, or to an image file.

    The SaveImage method can save to four different output types by using one of eight different overloaded parameter sets. For each output type, there is an option to save the chart image as it appears on the screen, or to save the chart image as a specified size.

    To save the chart image to the clipboard, simply specify an image format, the size parameter is not specified here:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    C1Chart1.SaveImage(System.Drawing.Imaging.ImageFormat.Bmp)
    

    To write code in C#

    C#
    Copy Code
    c1Chart1.SaveImage(System.Drawing.Imaging.ImageFormat.Bmp);
    

    To save the chart image to an image file, simply specify the pathname for the new image and an image format, the size parameter is not specified here:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    C1Chart1.SaveImage("C:\temp\ChartImages\CandleChart.bmp",_
     System.Drawing.Imaging.ImageFormat.Bmp)
    

    To write code in C#

    C#
    Copy Code
    c1Chart1.SaveImage("C:\\temp\\ChartImages\\CandleChart.bmp",
    System.Drawing.Imaging.ImageFormat.Bmp);
    

    To save the chart image to a stream, simply specify the stream object and an image format, the size parameter is not specified here:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim coutstream As New System.IO.MemoryStream()
    C1Chart1.SaveImage(coutstream, System.Drawing.Imaging.ImageFormat.Bmp)
    

    To write code in C#

    C#
    Copy Code
    System.IO.MemoryStream  coutstream = new System.IO.MemoryStream();
    c1Chart1.SaveImage(coutstream, System.Drawing.Imaging.ImageFormat.Bmp);
    

    To save the chart image as a byte array, simply specify the byte array, and an image format, the size parameter is not specified here:

    To write code in Visual Basic

    Visual Basic
    Copy Code
    Dim bytes() As Byte
    C1Chart1.SaveImage(bytes, System.Drawing.Imaging.ImageFormat.Bmp)
    

    To write code in C#

    C#
    Copy Code
    Byte[] bytes;
    c1Chart1.SaveImage(bytes, System.Drawing.Imaging.ImageFormat.Bmp);
    
    See Also