Xceed Chart for WinForms v4.4 Documentation
Image Export To File

Welcome to Xceed Chart for WinForms v4.4 > User Guide > Image Export > Image Export To File

The ImageExport object has a function called SaveToImageFile that allows you to export the image displayed by the component to a file in different file formats. This removes the need to create an ImageCodecInfo object just to specify a simple parameter such as quality in the case of a JPEG. The function has two versions:

VB.NET  

Public Sub SaveToImageFile(ByVal fileName As String, ByVal pixelFormat As PixelFormat, ByVal imageFormat As ImageFormat, ByVal quality As Integer, ByVal grayscale As Boolean)

 

Public Sub SaveToImageFile(ByVal fileName As String, ByVal dimensions As Size, ByVal pixelFormat As PixelFormat, ByVal imageFormat As ImageFormat, ByVal quality As Integer, ByVal grayscale As Boolean)

C#  

public void SaveToImageFile(String fileName, PixelFormat pixelFormat, ImageFormat imageFormat, int quality, bool grayscale)

 

public void SaveToImageFile(String fileName, Size dimensions, PixelFormat pixelFormat, ImageFormat imageFormat, int quality, bool grayscale)

The difference between the two versions of the function is that the fist one will generate an image whose dimensions are synchronized with the chart size in the form. The second version allows you to specify custom dimensions via the dimensions parameter. Let's look at the parameters of the function one by one:

The following code snippet illustrates how to work with the SaveToImageFile function:

VB.NET  

Dim imageExport As ImageExport =   chartControl.ImageExport

 

' exports a true color, 200x200, png image

imageExport.SaveToImageFile("c:\temp\checkpng.png", New Size(200, 200),

PixelFormat.Format32bppRgb, ImageFormat.Png, 100, False)

 

' exports a true color, 200x200, jpg image with small quality

imageExport.SaveToImageFile("c:\temp\checkjpg.jpg", New Size(200, 200),

PixelFormat.Format32bppRgb, ImageFormat.Png, 50, False)

 

' exports a grayscale, jpg image with small quality, synchronized with the control dimensions in the form

imageExport.SaveToImageFile("c:\temp\checkjpg.jpg", New Size(200, 200),

PixelFormat.Format32bppRgb, ImageFormat.Png, 50, False)

C#  

ImageExport imageExport = ChartControl.ImageExport;

 

// exports a true color, 200x200, png image
imageExport.SaveToImageFile("c:\\temp\\checkpng.png", new Size(200, 200), PixelFormat.Format32bppRgb, ImageFormat.Png, 100, false);

 

// exports a true color, 200x200, jpg image with small quality
imageExport.SaveToImageFile("c:\\temp\\checkjpg.jpg", new Size(200, 200), PixelFormat.Format32bppRgb, ImageFormat.Png, 50, false);

// exports a grayscale, jpg image with small quality, synchronized with the control dimensions in the form

imageExport.SaveToImageFile("c:\\temp\\checkjpg.jpg", new Size(200, 200), PixelFormat.Format32bppRgb, ImageFormat.Png, 50, false);

See also  

ChartControl | ChartServerControl | ImageExport