Silverlight export image to PNG

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
BlueMonkey
Newbie
Newbie
Posts: 34
Joined: Tue Nov 04, 2008 12:00 am

Silverlight export image to PNG

Post by BlueMonkey » Thu Jun 24, 2010 12:15 am

How can I export the TChart image to a file such as PNG in Silverlight?

I tried the code shown, but no file is produced. Is there sample code somewhere that I have not found?

Thanks,
Kent

Code: Select all

        private void buttonCopy_Click(object sender, RoutedEventArgs e)
        {
            //Stream myStream;
            string fileName;

            SaveFileDialog saveDialog = new SaveFileDialog();
            try
            {
                fileName = string.Format("Chart Image {0}", string.Format("{0:yyyy-MMM-dd}", DateTime.Now));
                //saveDialog.SafeFileName = fileName;

                saveDialog.DefaultExt = "png";
                saveDialog.Filter = "Chart image file (*.png)|*.png";
                saveDialog.FilterIndex = 1;
                //               saveDialog.Title = "Export Chart Data";

                if (saveDialog.ShowDialog() == true)
                {
                    FChartTimeSeries.ChartDisplay.Export.Image.PNG.Save(saveDialog.SafeFileName);
                    //FChartTimeSeries.ChartDisplay.Export.Image.PNG.Save(myStream);
                    //using (Stream stream = saveDialog.OpenFile())
                    //{
                    //    using (StreamWriter writer = new StreamWriter(stream))
                    //    {
                    //        writer.Write(myStream);
                    //    }
                    //}
                }
            }
            catch
            {
            }

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Silverlight export image to PNG

Post by Sandra » Fri Jun 25, 2010 12:17 pm

Hello Kent,

I made a simple example that works fine here with next maintenance release of TeeChartSilverlight and I think you can use similar code in your application for save image .png:

Code: Select all

 private Steema.TeeChart.Silverlight.Styles.Line line1;
       
        public void InitializeChart()
        {
             line1 = new Steema.TeeChart.Silverlight.Styles.Line(tChart1.Chart);
            line1.FillSampleValues();
         
        }
    
        void button1_Click(object sender, RoutedEventArgs e)
        {
            tChart1.Export.Image.PNG.Save("");

        } 
Could you please check if previous code works as you want?

I hope will helps.

Thanks,

BlueMonkey
Newbie
Newbie
Posts: 34
Joined: Tue Nov 04, 2008 12:00 am

Re: Silverlight export image to PNG

Post by BlueMonkey » Fri Jun 25, 2010 4:57 pm

Hi Sandra,

I will try it when the next release comes out. I am curious where the file will go, since Silverlight restrict exports to a folder that the user specifies, and the file name returned from the Save Dialog does not contain a folder name. In order to save ordinary files it is necessary to use the SaveDialog.OpenFile() method to directly open the file specified. Passing a complete file/path name to a different object's save method does not usually work.

Your example does not use the Save Dialog and passes an empty file name to the export method, so I don't know if that is required and if TeeChart supplies a name in this case. I would like for the user to be allowed to supply the file name.

I guess I will find all this out when I get the next maintenance release.

Thanks,
Kent

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: Silverlight export image to PNG

Post by Sandra » Wed Jun 30, 2010 9:34 am

Hello BlueMonkey,


Sorry for the delayed reply. I have tested your problem with Silverlight dialog and I inform that you can have two ways for save PNG image with TeeChartSilverlight.

First, you could save image with property tChart1.Export.Image.PNG.UseIsolatedStorage=true, it save your image in a hidden folder of the system where extensively explain in this link , if you are interest in it, you could use similar code as next:

Code: Select all

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            using (System.IO.IsolatedStorage.IsolatedStorageFile iso = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication())
             {
                 iso.IncreaseQuotaTo(50000000);
                }
    
                tChart1.Export.Image.PNG.UseIsolatedStorage = true;
                tChart1.Export.Image.PNG.Save("tmp.png");
        }
Second way, that I think more interesting for you, is saving an image with a dialog that TeeChartSilverlight it gives you.
It is a solution that I have proposes previously, but I think that I didn’t explain well. Using it you could save your image with name that you provide, you can a code as next:

Code: Select all

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Steema.TeeChart.Silverlight.Export.PNGFormat png = tChart1.Export.Image.PNG;
            png.UseIsolatedStorage = false;
            png.Save("");
        }
Also notice that it's useless saving an image providing a file name. Save method will open a save file dialog and will create an image with the file name given in the dialog. That's why file name is empty in my examples.
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply