Knowledgebase: Export to Bitmap
Export chart from screen to bitmap
Posted by Admin - on 21 March 2014 11:20 AM

Sometimes you need to save chart from screen to bitmap and insert it in some of your presentations or for further processing in photo editor. For this purpose SciChart have some useful features like saving chart from screen to different sources for further processing.

For now SciChart supports export chart to BitmapSource. To do it we provide next method in SciChartSurface class:

BitmapSource ExportToBitmapSource()



Also you can export chart to some of supported file formats. For now we support few graphical format such as:

  • PNG
  • JPEG
  • BMP

So if you want to save chart to some file you can you next method from SciChartSurface:

void ExportToFile(string fileName, ExportType exportType)

 

  • filename – path where you want to save bitmap;
  • exportType –  one of supported export types.

Note: This API doesn’t provide offscreen rendering of chart.

Using in real example

To show how to use this API we’re going to create some custom modifier which will save snapshots of chart to files in some folder. This action happens when we click right mouse button. Also we’ll add copying chart to clipboard on double click. To do it we need to derive from ChartModifierBase class and override few methods:

public class ExportToBitmapModifier : ChartModifierBase
{
    // Copying chart screenshot to clipboard on double click
    public override void OnModifierDoubleClick(ModifierMouseArgs e)
    {
        base.OnModifierDoubleClick(e);
        var surface = ParentSurface as SciChartSurface;
        if (surface != null)
        {
            // Export surface to BitmapSource
            var image = surface.ExportToBitmapSource();
            Clipboard.SetImage(image);
        }
    }

    // Saving screenshot of chart on right mouse click
    public override void OnModifierMouseDown(ModifierMouseArgs e)
    {
        base.OnModifierMouseDown(e);
        if (e.MouseButtons == MouseButtons.Right)
        {
            var saveFileDialog = new SaveFileDialog
            {
                Filter = "Png|*.png|Jpeg|*.jpeg|Bmp|*.bmp",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
            };

            if (saveFileDialog.ShowDialog() == true)
            {
                var surface = ParentSurface as SciChartSurface;
                if(surface == null)
                    return;

                var exportType = (ExportType)saveFileDialog.FilterIndex-1;
				
                // Saving chart to file with specified file format
                surface.ExportToFile(saveFileDialog.FileName,exportType);
            }
        }
    }
}

 

 

Screenshot made by ExportToBitmapModifier

 

(1 vote(s))
Helpful
Not helpful

CONTACT US

Not sure where to start? Contact us, we are happy to help!


CONTACT US

SciChart Ltd, 16 Beaufort Court, Admirals Way, Docklands, London, E14 9XL. Email: Legal Company Number: 07430048, VAT Number: 101957725