/// <summary>
        /// Saves annotation collection to a file.
        /// </summary>
        /// <param name="annotationViewer">The annotation viewer.</param>
        /// <param name="saveFileDialog">The save file dialog.</param>
        public static void SaveAnnotationsToFile(AnnotationViewer annotationViewer, SaveFileDialog saveFileDialog)
        {
            // cancel annotation building
            annotationViewer.CancelAnnotationBuilding();

            saveFileDialog.FileName    = null;
            saveFileDialog.Filter      = "Binary Annotations|*.vsab|XMP Annotations|*.xmp|WANG Annotations|*.wng";
            saveFileDialog.FilterIndex = 1;

            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    // open specified file
                    using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite))
                    {
                        // get annotation formatter

                        IFormatter formatter = null;
                        if (saveFileDialog.FilterIndex == 1)
                        {
                            formatter = new AnnotationVintasoftBinaryFormatter();
                        }
                        else if (saveFileDialog.FilterIndex == 2)
                        {
                            formatter = new AnnotationVintasoftXmpFormatter();
                        }
                        else if (saveFileDialog.FilterIndex == 3)
                        {
                            if (MessageBox.Show(
                                    "Important: some data from annotations will be lost. Do you want to continue anyway?",
                                    "Warning",
                                    MessageBoxButtons.OKCancel,
                                    MessageBoxIcon.Warning) == DialogResult.Cancel)
                            {
                                return;
                            }

                            formatter = new AnnotationWangFormatter(annotationViewer.Image.Resolution);
                        }

                        // get focused annotation data collection
                        AnnotationDataCollection annotations = annotationViewer.AnnotationDataController[annotationViewer.FocusedIndex];
                        // serialize annotation data to specified stream
                        formatter.Serialize(fs, annotations);
                    }
                }
                catch (Exception ex)
                {
                    DemosTools.ShowErrorMessage(ex);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Saves the measurement annotations to a file.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void saveMeasurementsAction_Clicked(object sender, EventArgs e)
        {
            using (SaveFileDialog saveFileDialog = new SaveFileDialog())
            {
                saveFileDialog.FileName    = null;
                saveFileDialog.Filter      = "Binary Annotations|*.vsabm|XMP Annotations|*.xmpm";
                saveFileDialog.FilterIndex = 1;

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        using (FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.Create, FileAccess.ReadWrite))
                        {
                            IFormatter formatter = null;
                            if (saveFileDialog.FilterIndex == 1)
                            {
                                formatter = new AnnotationVintasoftBinaryFormatter();
                            }
                            else if (saveFileDialog.FilterIndex == 2)
                            {
                                formatter = new AnnotationVintasoftXmpFormatter();
                            }

                            ImageMeasureTool         visualTool  = (ImageMeasureTool)VisualTool;
                            AnnotationDataCollection annotations = visualTool.AnnotationViewCollection.DataCollection;

                            formatter.Serialize(fs, annotations);
                        }
                    }
                    catch (Exception ex)
                    {
                        DemosTools.ShowErrorMessage(ex);
                    }
                }
            }
        }