C# 打印位图文件

C# 打印位图文件,c#,wpf,c#-4.0,printing,imaging,C#,Wpf,C# 4.0,Printing,Imaging,我编写了捕获屏幕截图并将其保存到WPF中的位图文件的代码 现在我想将位图发送到按打印机页面大小缩放的打印机 如何在WPF和C#中执行此操作?未询问用户就无法打印(打开打印对话框) 描述如何使用dialog执行此操作 PrintDialog dialog = new PrintDialog(); if (dialog.ShowDialog() == true) { dialog.PrintVisual(_PrintCanvas, "My Canvas"); } 还是你的情况 private vo

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

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


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

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

描述如何使用dialog执行此操作

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.");
}