printing chart to png - background

2 posts, 0 answers
  1. ITA
    ITA avatar
    383 posts
    Member since:
    Aug 2009

    Posted 16 Jul Link to this post

    Hi,

     

    print i chart with this code:

    string filename = "ExportedChart.png";
    using (Stream fileStream = File.Open(filename, FileMode.OpenOrCreate))
    {
        Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(this.chart, fileStream, new PngBitmapEncoder());
    }

     

    the problem ist, that the background of the png-file ist black! how can i change this to white?

    thanks a lot

    Rene

  2. Milena
    Admin
    Milena avatar
    204 posts

    Posted 18 Jul Link to this post

    Hello Rene,

    Thank you for the code-snippet provided.

    When you export the ChartView to png, the background of the image should be the same as the background of the ChartView. If you are using e.g. Expression_Dark theme or you have set Background property of the chart to black, then the image should have the same color.  However, you can change the Background of the chart only by export: 
    string filename = "ExportedChart.png";
    var initialColor = this.chart.Background;
    this.chart.Background = new SolidColorBrush(Colors.White);
    using (Stream fileStream = File.Open(filename, FileMode.OpenOrCreate))
    {
         Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(this.chart, fileStream, new PngBitmapEncoder());
    }
    this.chart.Background = initialColor;

    I hope this information helps.

    Regards,
    Milena
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top