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

Xceed Chart for WinForms can render in a .NET bitmap, which allows you to implement image export capabilities in your Windows Forms or ASP.NET (WebForms) application.

RenderToBitmap

This function accepts a .NET Bitmap object, to which the chart will render. The following code will generate a .png file from the chart currently displayed by the control:

VB.NET  

Dim bitmap As Bitmap = New Bitmap(200, 200, PixelFormat.Format24bppRgb)
chartControl1.ImageExport.RenderToBitmap(bitmap)
bitmap.Save("c:\temp\chartimage.png", ImageFormat.Png)
C#  
Bitmap bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
chartControl1.ImageExport.RenderToBitmap(bitmap);
bitmap.Save("c:\\temp\\chartimage.png", ImageFormat.Png);

The control will automatically render with the proper dimensions (synchronized with the dimensions of the passed bitmap).

RenderToBitmapGrayScale

This is similar to RenderToBitmap except that the generated image will be grayscaled. The control uses this function internally when printing in grayscale mode.

VB.NET  

Bitmap bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb)
chartControl1.ImageExport.RenderToBitmapGrayScale(bitmap)
bitmap.Save("c:\temp\grayscalechartimage.png", ImageFormat.Png)
C#  
Bitmap bitmap = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
chartControl1.ImageExport.RenderToBitmapGrayScale(bitmap);
bitmap.Save("c:\\temp\\grayscalechartimage.png", ImageFormat.Png);

RenderToHBitmap

This function generates a handle to a Windows GDI bitmap and can come in very handy in legacy applications that use the chart control via COM interop.

VB.NET  

Dim bitmapHandle As Integer = 0
chartControl1.ImageExport.RenderToHBitmap(200, 200, 24, bitmapHandle)
Dim bitmap As Bitmap = Bitmap.FromHbitmap(CType(bitmapHandle, IntPtr))
bitmap.Save("c:\temp\chartimage.png", ImageFormat.Png)
C#  
int bitmapHandle = 0;
chartControl1.ImageExport.RenderToHBitmap(200, 200, 24, ref bitmapHandle);
Bitmap bitmap = Bitmap.FromHbitmap((IntPtr)bitmapHandle);
bitmap.Save("c:\\temp\\chartimage.png", ImageFormat.Png);

Note that if you're using the chart via interop, you must delete the returned handle by calling DeleteObject on it. 

See also

ChartControl