Exemple #1
0
        private ImageEditor(string filename, Size size, bool allowNoCrop, Rect?startRect)
        {
            _model = new CropModel {
                TargetWidth  = size.Width,
                TargetHeight = size.Height
            };

            DataContext = this;
            InitializeComponent();

            Buttons = new[] {
                allowNoCrop?CreateExtraDialogButton(AppStrings.CropImage_Skip, new DelegateCommand(() => {
                    Result = (BitmapSource)_image.ImageSource;
                    ResultRect = new Int32Rect(0, 0, _image.Width, _image.Height);
                    ResultRectRelative = new Rect(0d, 0d, 1d, 1d);
                    Close();
                }, () => !_image.IsBroken)) : null,
                    CreateCloseDialogButton(UiStrings.Ok, true, false, MessageBoxResult.OK, new DelegateCommand(() => {
                    var rect = new Int32Rect((int)_model.OffsetX, (int)_model.OffsetY, (int)_model.ImageWidth, (int)_model.ImageHeight);

                    ResultRect         = rect;
                    ResultRectRelative = new Rect(
                        (double)rect.X / _image.Width, (double)rect.Y / _image.Height,
                        (double)rect.Width / _image.Width, (double)rect.Height / _image.Height);

                    var cropped = new CroppedBitmap((BitmapSource)_image.ImageSource, rect);
                    Result      = cropped.Resize((int)_model.TargetWidth, (int)_model.TargetHeight);
                }, () => !_image.IsBroken)),
                    CancelButton
            };

            LoadImage(filename, startRect).Forget();
            UpdateControlsToScale();
        }