Exemple #1
0
        private void RenderStillVisualisation_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            openDialog.FilterIndex = 0;
            openDialog.Title = "Select visualisation file";
            Nullable<bool> result = openDialog.ShowDialog();

            if (result == true)
            {
                string tempFileName = openDialog.FileName;
                //string tempFileName = @"C:\Users\Iman\Documents\Visual Studio 2012\Projects\CONVErT\CONVErT\Test\Working\HorBarchart.xml";
                try
                {
                    XAMLRenderer rend = new XAMLRenderer();
                    UIElement rendResult = rend.createStillVisualisation(tempFileName);
                    if (rendResult != null)
                    {
                        RenderCanvas.Children.Clear();
                        RenderCanvas.Children.Add(rendResult);

                        //log event
                        logger.log("Tried rendering still visualisation \"" + tempFileName + "\".");
                        DesignerTabControl.SelectedIndex = 2;
                        reportMessage("Still visualisation \"" + tempFileName + " rendered", ReportIcon.OK);
                    }
                }
                catch (Exception ex)
                {
                    reportMessage(ex.ToString(), ReportIcon.Error);
                }
            }
        }
Exemple #2
0
        private void ExportToPNG_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();
            openDialog.Title = "Select visualisation file";
            openDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
            openDialog.FilterIndex = 0;
            Nullable<bool> result = openDialog.ShowDialog();

            if (result == true)
            {
                string tempFileName = openDialog.FileName;
                //string tempFileName = @"C:\Users\Iman\Documents\Visual Studio 2012\Projects\CONVErT\CONVErT\Test\Working\HorBarchart.xml";
                try
                {
                    XAMLRenderer rend = new XAMLRenderer();
                    UIElement rendResult = rend.createStillVisualisation(tempFileName);

                    if (rendResult != null)
                    {
                        //get PNG file name
                        SaveFileDialog saveDialog = new SaveFileDialog();

                        saveDialog.Title = "Export to PNG";
                        saveDialog.Filter = "PNG files (*.png)|*.png|All files (*.*)|*.*";
                        saveDialog.FileName = "";
                        saveDialog.ShowDialog();

                        if (!saveDialog.FileName.Equals(""))
                        {
                            //resulted visualisation model file
                            string savePngFile = saveDialog.FileName;
                            //where the reaulted reverse will be saved

                            if (!savePngFile.ToLower().EndsWith(".png"))
                                savePngFile += ".png";

                            //save to file
                            using (Stream imageStream = File.Create(savePngFile))
                            {
                                Window wind = new Window();
                                wind.WindowStyle = WindowStyle.None;
                                wind.ShowInTaskbar = false;
                                wind.ShowActivated = false;

                                // Create Minimized so the window does not show. wind.WindowState = System.Windows.WindowState.Minimized;
                                wind.SizeToContent = SizeToContent.WidthAndHeight;

                                wind.Content = (UIElement)rendResult;
                                wind.Show(); // The window needs to be created for the XAML elements to be rendered.

                                BitmapSource bitmapSrc = visualToBitmap(wind, 100, 100);//dpiX, dpiY);
                                BitmapEncoder encoder = new PngBitmapEncoder();

                                encoder.Frames.Clear();
                                encoder.Frames.Add(BitmapFrame.Create(bitmapSrc));
                                encoder.Save(imageStream);

                                imageStream.Flush();

                                wind.Hide();
                            }
                        }
                        else
                            reportMessage("Failed to save PNG file!", ReportIcon.Error);
                    }
                    else
                        reportMessage("Export to PNG -> Rendered XAML returned empty!", ReportIcon.Error);
                }
                catch (Exception ex)
                {
                    reportMessage("Exception in Visualiser.ExportToPNG -> " + ex.Message, ReportIcon.Error);
                }
            }
        }