4

我编写了代码来捕获屏幕截图并将其保存到 WPF 中的位图文件中。

现在我想将位图发送到按打印机页面大小缩放的打印机。

如何在 WPF 和 C# 中执行此操作?

4

1 回答 1

5

不询问用户就无法打印(打开打印对话框)

本文描述了如何使用对话框进行操作

PrintDialog dialog = new PrintDialog();
if (dialog.ShowDialog() == true)
{ dialog.PrintVisual(_PrintCanvas, "My Canvas"); }

或者在你的情况下

private void PrintSomethingNew()
{
  PrintDialog dialog = new PrintDialog();
  if (dialog.ShowDialog() != true)
  { return; }

  StackPanel myPanel = new StackPanel();
  myPanel.Margin = new Thickness(15);
  Image myImage = new Image();
  myImage.Width = 128;
  myImage.Stretch = Stretch.Uniform;
  myImage.Source = new BitmapImage(new Uri("C:\\Tree.jpg", UriKind.Absolute));
  myPanel.Children.Add(myImage);
  TextBlock myBlock = new TextBlock();
  myBlock.Text = "A Great Image.";
  myBlock.TextAlignment = TextAlignment.Center;
  myPanel.Children.Add(myBlock);

  myPanel.Measure(new Size(dialog.PrintableAreaWidth,
    dialog.PrintableAreaHeight));
  myPanel.Arrange(new Rect(new Point(0, 0), 
    myPanel.DesiredSize));

  dialog.PrintVisual(myPanel, "A Great Image.");
}
于 2013-08-13T07:24:45.847 回答