Пример #1
0
        private void ActionSelected(object sender, RoutedEventArgs e)
        {
            ActionType at = (ActionType)Enum.Parse(typeof(ActionType), (string)(sender as Control).Tag);

            if (at == ActionType.Scale || at == ActionType.ChangeCanvasSize)
            {
                SizeDialogBox sdb = new SizeDialogBox(at == ActionType.Scale)
                {
                    Values_Width       = bmp.Width,
                    Values_Height      = bmp.Height,
                    Values_XResolution = bmp.XResolution,
                    Values_YResolution = bmp.YResolution
                };
                sdb.Owner = this;
                var res = sdb.ShowDialog();
                if (res.HasValue)
                {
                    if (res.Value)
                    {
                        if (at == ActionType.Scale)
                        {
                            bmp.Scale(sdb.Values_Width, sdb.Values_Height, sdb.Values_XResolution, sdb.Values_YResolution);
                        }
                        else
                        {
                            bmp.ChangeCanvasSize(sdb.Values_Width, sdb.Values_Height);
                        }

                        bmp.Apply();
                        bmp.SaveCheckpoint();
                    }
                }
            }
            switch (at)
            {
            case ActionType.Rotate_90C:
                bmp.Rotate_90C();
                break;

            case ActionType.Rotate_90CC:
                bmp.Rotate_90CC();
                break;

            case ActionType.Rotate_180:
                bmp.Rotate_180();
                break;

            case ActionType.Flip_Horizontal:
                bmp.Flip_Horizontal();
                break;

            case ActionType.Flip_Vertical:
                bmp.Flip_Vertical();
                break;

            default:
                break;
            }
            bmp.Apply();
            bmp.SaveCheckpoint();
        }
Пример #2
0
        private void CommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            RoutedUICommand cmd = e.Command as RoutedUICommand;

            switch (cmd.Name)
            {
            case "Undo": bmp.Undo(); break;

            case "Redo": bmp.Redo(); break;

            case "Close": this.Close(); break;

            case "New":
                SizeDialogBox sdb = new SizeDialogBox()
                {
                    Values_Width       = bmp.Width,
                    Values_Height      = bmp.Height,
                    Values_XResolution = bmp.XResolution,
                    Values_YResolution = bmp.YResolution
                };

                sdb.Owner = this;
                var res = sdb.ShowDialog();

                if (res.HasValue)
                {
                    if (res.Value)
                    {
                        bmp = new Bgra32BitmapTool(
                            sdb.Values_Width,
                            sdb.Values_Height,
                            sdb.Values_XResolution,
                            sdb.Values_YResolution
                            );
                        bmp.PropertyChanged += Bmp_PropertyChanged;
                        this.CurrentFilePath = null;
                    }
                }
                break;

            case "Open":
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.Filter = "Supported image files (*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tif;*.tiff;*.ico)|*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tif;*.tiff;*.ico|All files (*.*)|*.*";
                if (ofd.ShowDialog() == true)
                {
                    bmp = new Bgra32BitmapTool(new Uri(ofd.FileName, UriKind.RelativeOrAbsolute));
                    bmp.PropertyChanged += Bmp_PropertyChanged;
                    this.CurrentFilePath = ofd.FileName;
                }
                break;

            case "SaveAs":
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Supported image files (*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tif;*.tiff;*.ico)|*.png;*.jpg;*.jpeg;*.bmp;*.gif;*.tif;*.tiff;*.ico|All files (*.*)|*.*";
                if (sfd.ShowDialog() == true)
                {
                    this.CurrentFilePath = sfd.FileName;
                    this.GetCommand("Save")?.Execute(null, null);
                }
                break;

            case "Save":
                if (string.IsNullOrEmpty(this.CurrentFilePath))
                {
                    this.GetCommand("SaveAs")?.Execute(null, null);
                }
                else
                {
                    do
                    {
                        try
                        {
                            switch (this.CurrentFileExtension)
                            {
                            case ".bmp":
                                bmp.SaveBmp(this.CurrentFilePath);
                                break;

                            case ".gif":
                                bmp.SaveGif(this.CurrentFilePath);
                                break;

                            case ".jpg":
                            case ".jpeg":
                                bmp.SaveJpeg(this.CurrentFilePath);
                                break;

                            case ".png":
                                bmp.SavePng(this.CurrentFilePath);
                                break;

                            case ".tiff":
                                bmp.SaveTiff(this.CurrentFilePath);
                                break;

                            case ".wmp":
                                bmp.SaveWmp(this.CurrentFilePath);
                                break;

                            default:
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBoxResult mbr = MessageBox.Show(ex.Message, "Try again?", MessageBoxButton.YesNo, MessageBoxImage.Error);
                            if (mbr == MessageBoxResult.Yes)
                            {
                                continue;
                            }
                        }
                        break;
                    } while (true);
                }
                break;

            default:
                break;
            }
        }