private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (_croppingWindow != null)
            {
                return;
            }
            OpenFileDialog op = new OpenFileDialog();

            op.Title  = "Select a picture";
            op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                        "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                        "Portable Network Graphic (*.png)|*.png";
            if (op.ShowDialog() == true)
            {
                _croppingWindow         = new CroppingWindow();
                _croppingWindow.Closed += (a, b) => _croppingWindow = null;
                _croppingWindow.Height  = new BitmapImage(new Uri(op.FileName)).Height;
                _croppingWindow.Width   = new BitmapImage(new Uri(op.FileName)).Width;

                _croppingWindow.SourceImage.Source = new BitmapImage(new Uri(op.FileName));
                _croppingWindow.SourceImage.Height = new BitmapImage(new Uri(op.FileName)).Height;
                _croppingWindow.SourceImage.Width  = new BitmapImage(new Uri(op.FileName)).Width;

                _croppingWindow.Show();
            }
        }
Example #2
0
        private void Load_Image()
        {
            if (image_list.Count > 0)
            {
                _croppingWindow         = new CroppingWindow();
                _croppingWindow.Closed += (a, b) => _croppingWindow = null;
                _croppingWindow.Height  = new BitmapImage(new Uri(image_list[0])).Height;
                _croppingWindow.Width   = new BitmapImage(new Uri(image_list[0])).Width;

                _croppingWindow.SourceImage.Source = new BitmapImage(new Uri(image_list[0]));
                _croppingWindow.SourceImage.Height = new BitmapImage(new Uri(image_list[0])).Height;
                _croppingWindow.SourceImage.Width  = new BitmapImage(new Uri(image_list[0])).Width;
                _croppingWindow.Show();
            }
            else
            {
                this.Close();
            }
        }
        private void Button_LoadImage(object sender, RoutedEventArgs e)
        {
            if (_croppingWindow != null)
            {
                return;
            }
            OpenFileDialog op = new OpenFileDialog
            {
                Title  = "Select a picture",
                Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"
            };

            if (op.ShowDialog() != true)
            {
                return;
            }

            sourceBitmap = new BitmapImage(new Uri(op.FileName));

            _croppingWindow         = new CroppingWindow();
            _croppingWindow.Closed += (a, b) => _croppingWindow = null;


            double maxWidth  = Math.Min(SystemParameters.PrimaryScreenWidth - 300, sourceBitmap.PixelWidth);
            double maxHeight = Math.Min(SystemParameters.PrimaryScreenHeight - 300, sourceBitmap.PixelHeight);

            AspectRatio = Math.Min(maxWidth / sourceBitmap.PixelWidth, maxHeight / sourceBitmap.PixelHeight);
            ImageWidth  = sourceBitmap.PixelWidth * AspectRatio;
            ImageHeight = sourceBitmap.PixelHeight * AspectRatio;

            _croppingWindow.Width  = ImageWidth;
            _croppingWindow.Height = ImageHeight;
            _croppingWindow.SetImage(new BitmapImage(new Uri(op.FileName)), ImageWidth, ImageHeight);


            _croppingWindow.Show();
        }