【问题标题】:Printing an Bitmap File打印位图文件
【发布时间】:2013-08-13 07:18:57
【问题描述】:

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

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

如何在 WPF 和 C# 中做到这一点?

【问题讨论】:

    标签: c# wpf c#-4.0 printing imaging


    【解决方案1】:

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

    This article 描述如何使用对话框进行操作

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 2014-12-13
      相关资源
      最近更新 更多