private void SaveToImageFile() { if (_screenBitmap != null) { Rect rect = this.rectClip.Rect; double wpfDpi = 96; wpfDpi = _sysDpi / wpfDpi; double rateDpi = wpfDpi;// _screenScale * wpfDpi; var clip = new System.Drawing.Rectangle((int)(rect.X * rateDpi), (int)(rect.Y * rateDpi), (int)(rect.Width * rateDpi), (int)(rect.Height * rateDpi)); string root = SDKClient.SDKClient.Instance.property.CurrentAccount.imgPath; if (!System.IO.Directory.Exists(root)) { System.IO.Directory.CreateDirectory(root); } _clipSavePath = System.IO.Path.Combine(root, $"{Guid.NewGuid().ToString()}.jpg"); BitmapSource source = ImageDeal.SaveUiToImageFile(this.canvasMain, clip, rateDpi, _clipSavePath); if (source == null) { _clipSavePath = null; } else { Clipboard.SetImage(source); } } this.DialogResult = true; }
private void stkpMenu_Click(object sender, RoutedEventArgs e) { List <string> list = new List <string>(); Color c; ButtonBase button = e.Source as ButtonBase; switch (button.Uid) { case "Pen": this.bdThumb.IsHitTestVisible = false; this.inkCanvas.Visibility = Visibility.Visible; break; case "Save": Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); sfd.Filter = "JPEG (*.jpg;*.jpeg)|*.jpg|BMP (*.bmp)|*.bmp|PNG (*.png)|*.png"; sfd.FileName = string.Format("IM截图{0}.jpg", DateTime.Now.ToString("yyyyMMddHHmmss")); sfd.FilterIndex = 1; sfd.RestoreDirectory = true; if (sfd.ShowDialog() == true) { Rect clip = this.rectClip.Rect; double wpfDpi = 96; wpfDpi = _sysDpi / wpfDpi; double rateDpi = _screenScale * wpfDpi; var sourceRect = new System.Drawing.Rectangle((int)(clip.X * rateDpi), (int)(clip.Y * rateDpi), (int)(clip.Width * rateDpi), (int)(clip.Height * rateDpi)); BitmapSource source = ImageDeal.SaveUiToImageFile(this.canvasMain, sourceRect, rateDpi, sfd.FileName); if (source != null) { Clipboard.SetImage(source); this.DialogResult = false; } } break; case "Backout": if (this.inkCanvas.Strokes.Count > 0) { this.inkCanvas.Strokes.RemoveAt(this.inkCanvas.Strokes.Count - 1); this.rbtnBackout.IsEnabled = this.inkCanvas.Strokes.Count > 0; } break; case "Cancel": this.DialogResult = false; break; case "OK": SaveToImageFile(); break; } }