Exemplo n.º 1
0
        private void save()
        {
            Stream SaveFileStream = File.Create(Morpher.PROJECT_PATH + Morpher.PROJECT_NAME
                                                + "\\" + Morpher.PROJECT_NAME);
            BinaryFormatter    serializer = new BinaryFormatter();
            ProjectPersistence save       = new ProjectPersistence();

            save.DestControlDict   = destViewer.ControlLineDict;
            save.DestControlLines  = destViewer.ControlLines;
            save.DestImageFilename = destViewer.ImgFileName;
            save.SrcControlDict    = srcViewer.ControlLineDict;
            save.SrcControlLines   = srcViewer.ControlLines;
            save.SrcImageFilename  = srcViewer.ImgFileName;
            save.StartColour       = ControlLineVisual.START_COLOUR;
            save.MiddleColour      = ControlLineVisual.MIDDLE_COLOUR;
            save.EndColour         = ControlLineVisual.END_COLOUR;
            save.LineColour        = ControlLineVisual.LINE_COLOUR;
            save.HighlightColour   = ControlLineVisual.HIGHLIGHT_COLOUR;
            save.LineThickness     = ControlLineVisual.LINE_THICKNESS;
            save.Diameter          = ControlLineVisual.DIAMETER;
            save.Tolerance         = ControlPoint.TOLERANCE;
            save.ProjectName       = Morpher.PROJECT_NAME;
            save.ProjectPath       = Morpher.PROJECT_PATH;
            save.MorphNames        = new Dictionary <string, int>();
            foreach (String key in morphViewer.morphDict.Keys)
            {
                save.MorphNames.Add(key, morphViewer.morphDict[key].Frames.Count);
            }
            serializer.Serialize(SaveFileStream, save);
            SaveFileStream.Close();
        }
Exemplo n.º 2
0
        private void OpenProject_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
                Stream openFileStream = File.OpenRead(openFileDialog.FileName);
                srcViewer.image.Source  = null;
                destViewer.image.Source = null;
                BinaryFormatter deserializer = new BinaryFormatter();
                //must be temporarily set to 0 to ensure it's lower than saved tolerance due to sorted dictionary
                ControlPoint.TOLERANCE = 0;
                ProjectPersistence loaded = (ProjectPersistence)deserializer.Deserialize(openFileStream);
                loadSettings(loaded);
                morphViewer.morphDict.Clear();
                if (loaded.MorphNames.Count > 0)
                {
                    foreach (string key in loaded.MorphNames.Keys)
                    {
                        Morph morph = new Morph();
                        morph.Frames = new List <BitmapSource>();
                        for (int j = 0; j < loaded.MorphNames[key]; j++)
                        {
                            BitmapSource bms = Morpher.LoadImage(loaded.ProjectPath + loaded.ProjectName + "\\" + key
                                                                 + "_" + j + ".png");
                            morph.Frames.Add(bms);
                        }
                        morph.MorphName = key;
                        morphViewer.morphDict.Add(key, morph);
                        modeItem.IsEnabled = true;
                    }
                }
                Morpher.PROJECT_NAME = loaded.ProjectName;
                Morpher.PROJECT_PATH = loaded.ProjectPath;
                srcViewer.loadProject(loaded.SrcControlLines, loaded.SrcControlDict, loaded.SrcImageFilename);
                destViewer.loadProject(loaded.DestControlLines, loaded.DestControlDict,
                                       loaded.DestImageFilename);
                openFileStream.Close();
                morphViewer.Src  = srcViewer.ImageSrc;
                morphViewer.Dest = destViewer.ImageSrc;
                morphViewer.updateMorphs();
                manageItem.IsEnabled  = true;
                morphItem.IsEnabled   = true;
                modeItem.IsEnabled    = true;
                setsrcItem.IsEnabled  = true;
                setdestItem.IsEnabled = true;
                Mouse.OverrideCursor  = System.Windows.Input.Cursors.Arrow;
            }
        }
Exemplo n.º 3
0
 private void loadSettings(ProjectPersistence loaded)
 {
     settings.clSettings.load(loaded.LineThickness, loaded.Diameter, loaded.Tolerance, loaded.LineColour,
                              loaded.StartColour, loaded.MiddleColour, loaded.EndColour, loaded.HighlightColour);
 }