Exemplo n.º 1
0
        private void MenuItem_SaveAs_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            SaveFileDialog _SaveAsFile_dlg = new SaveFileDialog();

            _SaveAsFile_dlg.AddExtension    = true;
            _SaveAsFile_dlg.OverwritePrompt = true;
            _SaveAsFile_dlg.FileName        = "Новое изображение";
            _SaveAsFile_dlg.Filter         += "BMP (*.bmp)|*.bmp";
            _SaveAsFile_dlg.Filter         += "|GIF (*.gif)|*.gif";
            _SaveAsFile_dlg.Filter         += "|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif";
            _SaveAsFile_dlg.Filter         += "|PNG (*.png)|*.png";
            _SaveAsFile_dlg.Filter         += "|TIFF (*.tif, *.tiff)|*.tif;*.tiff";
            _SaveAsFile_dlg.Filter         += "|WMPhoto (*.wdp, *.wmp, *.hdp)|*.wdp;*.wmp;*.hdp";
            _SaveAsFile_dlg.Filter         += "|TGA (*.tga)|*.tga";
            _SaveAsFile_dlg.Filter         += "|DirectDraw Surface (DDS) (*.dds)|*.dds";
            _SaveAsFile_dlg.Title           = "Сохранить как";
            if (_SaveAsFile_dlg.ShowDialog() == true)
            {
                try
                {
                    FileManagementController.SaveImageRender(imageCanvas, _SaveAsFile_dlg.FileName, this.imageCanvas.openfileRes);
                    this.imageCanvas.OpenfileName = _SaveAsFile_dlg.FileName;
                    OpenfileNameChanged(this, new EventArgs());
                    this.imageCanvas.lastChangeSaved = true;
                }
                catch (Exception)
                {
                    MessageBox.Show("Невозможно сохранить изображение", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemplo n.º 2
0
 private void MenuItem_Save_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         FileManagementController.SaveImageRender(imageCanvas, this.imageCanvas.OpenfileName, this.imageCanvas.openfileRes);
         this.imageCanvas.lastChangeSaved = true;
     }
     catch (Exception)
     {
         MessageBox.Show("Невозможно сохранить изображение", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 3
0
 private void Button_Ok_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         (this.Owner as MainWindow).imageCanvas.AddFirstLayer(FileManagementController.CreateImage(Convert.ToInt32(_TextBox_width_dock_1.Text), Convert.ToInt32(_TextBox_height_dock_2.Text)));
         int width = Convert.ToInt32(_TextBox_width_dock_1.Text), height = Convert.ToInt32(_TextBox_height_dock_2.Text);
         (this.Owner as MainWindow).borderCanvas.Width       = width;
         (this.Owner as MainWindow).borderCanvas.Height      = height;
         (this.Owner as MainWindow).imageBorder.Visibility   = System.Windows.Visibility.Visible;
         (this.Owner as MainWindow).imageCanvas.OpenfileName = "Новый документ";
         this.Close();
     }
     catch
     {
         MessageBox.Show("Ошибка при создании файла", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 4
0
        private void MenuItem_Open_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            if (!this.imageCanvas.lastChangeSaved)
            {
                MessageBoxResult res = MessageBox.Show("Сохранить текущее изображение?", "Внимание", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.Yes);
                if (res == MessageBoxResult.Yes)
                {
                    if (ApplicationCommands.Save.CanExecute(null, this))
                    {
                        ApplicationCommands.Save.Execute(null, this);
                    }
                    else
                    {
                        ApplicationCommands.SaveAs.Execute(null, this);
                    }
                }
                else if (res == MessageBoxResult.Cancel)
                {
                    e.Handled = true;
                    return;
                }
            }
            OpenFileDialog _OpenFile_dlg = new OpenFileDialog();

            _OpenFile_dlg.AddExtension = true;
            _OpenFile_dlg.Filter       = "Все типы изображений (*.bmp, *.gif, *.jpg, *.jpeg, *.jpe, *.jfif, *.png, *.tif, *.tiff, *.wdp, *wmp, *hdp, *.tga, *.dds)|*.bmp;*.gif;*.jpg;*.jpeg;*.jpe;*.jfif;*.png;*.tif;*.tiff;*wdp;*wmp;*hdp;*.tga;*.dds";
            _OpenFile_dlg.Filter      += "|BMP (*.bmp)|*.bmp";
            _OpenFile_dlg.Filter      += "|GIF (*.gif)|*.gif";
            _OpenFile_dlg.Filter      += "|JPEG (*.jpg, *.jpeg, *.jpe, *.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif";
            _OpenFile_dlg.Filter      += "|PNG (*.png)|*.png";
            _OpenFile_dlg.Filter      += "|TIFF (*.tif, *.tiff)|*.tif;*.tiff";
            _OpenFile_dlg.Filter      += "|WMPhoto (*.wdp, *.wmp, *.hdp)|*.wdp;*.wmp;*.hdp";
            _OpenFile_dlg.Filter      += "|TGA (*.tga)|*.tga";
            _OpenFile_dlg.Filter      += "|DirectDraw Surface (DDS) (*.dds)|*.dds";
            _OpenFile_dlg.Multiselect  = false;
            _OpenFile_dlg.Title        = "Открыть";
            if (_OpenFile_dlg.ShowDialog() == true)
            {
                try
                {
                    BitmapImage bmp = FileManagementController.OpenImage(_OpenFile_dlg.FileName);
                    this.imageCanvas.Clear();
                    borderCanvas.Width  = bmp.Width;
                    borderCanvas.Height = bmp.Height;
                    this.imageCanvas.AddFirstLayer(bmp);
                    this.imageCanvas.OpenfileName = _OpenFile_dlg.FileName;
                    OpenfileNameChanged(this, new EventArgs());
                    imageBorder.Visibility           = System.Windows.Visibility.Visible;
                    this.imageCanvas.lastChangeSaved = true;
                    if (LayerControl.IsCreated)
                    {
                        layerDialog.UpdateLayersControl();
                    }
                }
                catch (FileFormatException excp)
                {
                    MessageBox.Show(excp.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                catch (Exception)
                {
                    MessageBox.Show("Невозможно открыть изображение", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    this.UpdateLayout();
                }
            }
        }