Nevron Open Vision Documentation
Chart / Export / Chart Raster Image Export
In This Topic
    Chart Raster Image Export
    In This Topic

    The NChartRasterImageExporter lets you export the content of the active page (or portions of it) to a raster image in the following file formats:

     Saving with Dialog

    The following code shows how to display the default raster image export dialog provided by NOV:

    Showing the default raster image export dialog
    Copy Code
    NChartRasterImageExporter imageExporter = new NChartRasterImageExporter(chartView.Content);
    imageExporter.ShowDialog(DisplayWindow, true);
    

    The following code shows a save image file dialog that allows the user to create an image from a chart:

    Saving with a save file dialog
    Copy Code
    NChartRasterImageExporter imageExporter = new NChartRasterImageExporter(chartView.Content);
    imageExporter.SaveAsImage(NImageFormat.Png); // Save to image with PNG file format selected by default
    
     Saving to File or Stream

    To export chart to raster image and save it directly to a file, without showing a save file dialog, use the SaveToFile method. Note that the saving to file is an asynchronous (async) operation, so if you are interested in its completion, you should call the Then method of the promise it returns and handle the completion of the export in the passed delegate. The following is a code example:

    Saving to a file
    Copy Code
    NChartRasterImageExporter imageExporter = new NChartRasterImageExporter(chartView.Content);
    imageExporter.SaveToFileAsync("C:\\ExportedImage.png").Then(
        delegate (NUndefined ud)
        {
            // Export to PNG completed
        }
    );
    
    Exporting a chart to an arbitrary file works only on non-sandboxed platforms like WinForms, WPF and Xamarin.Mac.

    To export a chart to an image stream, use the SaveToStream method. Unlike the SaveToFile method, the SaveToStream method runs synchronously and blocks code execution until it completes. Exporting charts to stream is useful when you wish to generate images in memory instead of saving them to the disc. The following code snippet shows how to export the active page of a chart to a stream:

    Saving to a stream
    Copy Code
    NChartRasterImageExporter imageExporter = new NChartRasterImageExporter(chartView.Content);
    imageExporter.SaveToStream(stream, NImageFormat.Png);
    
     Generating a Raster Image

    To generate an image on the fly without saving it, use the CreateImage method:

    Generating Image
    Copy Code
    NChartRasterImageExporter imageExporter = new NChartRasterImageExporter(chartView.Content);
    NImage image = imageExporter.CreateImage();
    
     Copying to Clipboard

    To copy the image to the clipboard, use the CopyToClipboard method:

    Generating Image
    Copy Code
    NChartRasterImageExporter imageExporter = new NChartRasterImageExporter(chartView.Content);
    imageExporter.CopyToClipboard();
    
    See Also