コード例 #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            this.ShutdownMode = ShutdownMode.OnExplicitShutdown;
            taskTrayForm      = new TaskTrayForm();

            InputHistoryList.Instance().LoadHistory();
        }
コード例 #2
0
 public void UpdateAutoCompOutputFileNameSource()
 {
     // フォルダパス
     if (_AutoCompOutputFileNameSource == null)
     {
         _AutoCompOutputFileNameSource = new ObservableCollection <string>();
     }
     foreach (var elem in InputHistoryList.Instance().InputHistory.OutputFileNameHistory)
     {
         if (_AutoCompOutputFileNameSource.Contains(elem) == false)
         {
             _AutoCompOutputFileNameSource.Add(elem);
         }
     }
 }
コード例 #3
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            ErrorMessageLabel.Foreground = new SolidColorBrush(Colors.Red);
            ErrorMessageLabel.Text       = "";

            // エラーチェック
            // ...出力フォルダパス検査
            if (string.IsNullOrEmpty(OutputFolderPath.Text) == true)
            {
                ErrorMessageLabel.Text = "出力フォルダパスを入力してください";
                return;
            }

            if (Directory.Exists(this.OutputFolderPath.Text) == false)
            {
                ErrorMessageLabel.Text = "出力フォルダが存在しません";
                return;
            }

            // ...ファイル名禁則文字チェック
            char[] invalidChars = System.IO.Path.GetInvalidFileNameChars();
            if (string.IsNullOrEmpty(FileName.Text) == false && FileName.Text.IndexOfAny(invalidChars) >= 0)
            {
                ErrorMessageLabel.Text = "ファイル名に禁則文字が含まれています";
                return;
            }

            // レイアウトを再計算させる
            var size = new System.Windows.Size(ImageEditCanvas.RenderSize.Width, ImageEditCanvas.RenderSize.Height);

            ImageEditCanvas.Measure(size);
            ImageEditCanvas.Arrange(new Rect(size));

            // VisualObjectをBitmapに変換する
            var renderBitmap = new RenderTargetBitmap(
                (int)size.Width,
                (int)size.Height,
                96.0d,
                96.0d,
                PixelFormats.Pbgra32);

            renderBitmap.Render(ImageEditCanvas);

            // ファイルパスを作成
            var fileName = this.FileName.Text;

            if (string.IsNullOrEmpty(fileName) == true)
            {
                fileName = DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff");
            }
            if (fileName.Contains(".png") == false)
            {
                fileName += ".png";
            }

            var path = System.IO.Path.Combine(this.OutputFolderPath.Text, fileName);

            // 出力用のFileStreamを作成する
            using (var os = new FileStream(path, FileMode.Create))
            {
                // 変換したBitmapをエンコードしてFileStreamに保存する。
                // BitmapEncoder が指定されなかった場合は、PNG形式とする。
                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                encoder.Save(os);

                ErrorMessageLabel.Foreground = new SolidColorBrush(Colors.Blue);
                ErrorMessageLabel.Text       = "出力完了";
            }

            // 履歴ファイル出力
            InputHistoryList.Instance().AddOutputFolder(this.OutputFolderPath.Text);
            if (string.IsNullOrEmpty(this.FileName.Text) == false)
            {
                InputHistoryList.Instance().AddOutputFileName(this.FileName.Text);
            }
            InputHistoryList.Instance().OutputHistory();

            // オードコンプリートに追加
            var autoComp = DataContext as CaptureEditViewModel;

            autoComp.UpdateAutoCompOutputFolderPathSource();
            autoComp.UpdateAutoCompOutputFileNameSource();
        }