Beispiel #1
0
        private async Task LoadImage(string filename, Rect?startRect)
        {
            _image = await BetterImage.LoadBitmapSourceAsync(filename);

            OriginalImage.SetCurrentValue(Image.SourceProperty, _image.ImageSource);
            CommandManager.InvalidateRequerySuggested();

            if (_image.IsBroken)
            {
                NonfatalError.Notify(AppStrings.Dialogs_ImageEditor_CantLoadImage);
                CloseWithResult(MessageBoxResult.Cancel);
            }
            else
            {
                _model.TotalWidth  = MainGrid.Width = _image.Width;
                _model.TotalHeight = MainGrid.Height = _image.Height;
                _model.CalculateMinAndMax();

                if (startRect.HasValue)
                {
                    var rect = startRect.Value;
                    _model.OffsetX     = rect.X;
                    _model.OffsetY     = rect.Y;
                    _model.ImageWidth  = rect.Width;
                    _model.ImageHeight = rect.Height;
                }
                else
                {
                    _model.CenterAndFit();
                }

                UpdateView();
            }
        }