private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     _lines.Selected = null;
     using (OpenFileDialog ofd = new OpenFileDialog()) {
         ofd.Filter = "Morph Files (*.morph)|*.morph|All Files (*.*)|*.*";
         if (ofd.ShowDialog(this) == DialogResult.OK)
         {
             var formatter = new BinaryFormatter();
             using (Stream fileStream = ofd.OpenFile()) {
                 SavedSettings ss = (SavedSettings)formatter.Deserialize(fileStream);
                 _lines         = ss.Lines;
                 _morphSettings = ss.Settings;
                 ConfigurePictureBoxes(_lines, ss.FirstImage, ss.SecondImage);
             }
         }
     }
 }
Exemple #2
0
        private void PrepareUIDataForMorph(
            out UiSettings settings, out LinePairCollection lines,
            out Bitmap newStartImage, out Bitmap newEndImage)
        {
            // Grab UI data
            settings = Utilities.DeepClone(_morphSettings);
            lines    = Utilities.DeepClone(_lines);

            // Get the original iamges
            var origStartImage = (Bitmap)pbStartImage.Image;
            var origEndImage   = (Bitmap)pbEndImage.Image;

            // Get a scale factor from the UI
            float startImageScaleFactor = int.Parse(outputSizeToolStripTextBox.Text) / 100f;

            // Create the starting and ending images.  The starting image is scaled by the UI setting,
            // and the ending image is created to match the starting image's size.
            newStartImage = Utilities.CreateNewBitmapFrom(origStartImage, startImageScaleFactor);
            newEndImage   = Utilities.CreateNewBitmapFrom(origEndImage, newStartImage.Width, newStartImage.Height);

            // Get a scale factor by comparing the new and old ending images
            var endImageScaleFactor = new PointF(
                newEndImage.Width / (float)origEndImage.Width,
                newEndImage.Height / (float)origEndImage.Height);

            // Create new line pairings to cope with the scaling
            var newlineList =
                (from pair in _lines
                 select Tuple.Create(
                     new Line(
                         new PointF(pair.Item1.Item1.X * startImageScaleFactor, pair.Item1.Item1.Y * startImageScaleFactor),
                         new PointF(pair.Item1.Item2.X * startImageScaleFactor, pair.Item1.Item2.Y * startImageScaleFactor)),
                     new Line(
                         new PointF(pair.Item2.Item1.X * endImageScaleFactor.X, pair.Item2.Item1.Y * endImageScaleFactor.Y),
                         new PointF(pair.Item2.Item2.X * endImageScaleFactor.X, pair.Item2.Item2.Y * endImageScaleFactor.Y)))).ToList();

            lines = new LinePairCollection(newlineList);
        }