Ejemplo n.º 1
0
        private void picOriginal_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!MouseHelper.IsSelecting)
            {
                return;
            }
            MouseHelper.IsSelecting = false;

            MouseHelper.Point2 = Mouse.GetPosition(mainControl.OriginalImageCanvas);

            System.Windows.Media.Brush brush = new SolidColorBrush(Colors.Red);
            DrawHelper.DrawAndGetRectangle(mainControl.OriginalImageCanvas,
                                           new System.Windows.Point(Math.Min(MouseHelper.Point1.X, MouseHelper.Point2.X), Math.Min(MouseHelper.Point1.Y, MouseHelper.Point2.Y)),
                                           new System.Windows.Point(Math.Max(MouseHelper.Point1.X, MouseHelper.Point2.X), Math.Max(MouseHelper.Point1.Y, MouseHelper.Point2.Y)),
                                           brush);

            int width  = (int)Math.Abs(MouseHelper.Point2.X - MouseHelper.Point1.X);
            int height = (int)Math.Abs(MouseHelper.Point2.Y - MouseHelper.Point1.Y);

            MouseHelper.CorrectPoints(height, width);

            if ((width < 1) || (height < 1))
            {
                return;
            }

            mainControl.ProcessedGrayscaleImage      = Tools.CropImage(mainControl.OriginalGrayscaleImage, MouseHelper.Point1, MouseHelper.Point2);
            MouseHelper.IsSelecting                  = false;
            mainControl.OriginalImageCanvas.MouseUp -= new MouseButtonEventHandler(picOriginal_MouseUp);

            MessageBox.Show("Abaterea medie patratica: " + Tools.AverageSquareDerivation(mainControl.ProcessedGrayscaleImage, width, height).ToString());

            DrawHelper.RemoveAllRectangles(mainControl.OriginalImageCanvas);
        }