代码之家  ›  专栏  ›  技术社区  ›  James Jones

打印WPF位图图像

  •  5
  • James Jones  · 技术社区  · 17 年前

    打印位图图像的最佳方式是什么?我来自System.Drawing的背景,所以我想把它转换成位图,然后打印出来,但我想可能有更好的方法。

    谢谢!

    2 回复  |  直到 17 年前
        1
  •  5
  •   illogical    17 年前

    PrintDialog dlg = new PrintDialog();
    bool? result = dlg.ShowDialog();
    
    if (result.HasValue && result.Value)
    {
        ImageViewer.Measure(new Size(dlg.PrintableAreaWidth, dlg.PrintableAreaHeight));
        ImageViewer.Arrange(new Rect(new Point(0, 0), ImageViewer1.DesiredSize));
    
        dlg.PrintVisual(ImageViewer, "Print a Large Image");
    }
    

    在我的示例中,ImageViewer可以替换为任何UIElement容器,如stackpanel、canvas、grid等。ImageViewer.Source应设置为准备打印的BitmapImage。

    我从这一页得到了这个想法: http://www.switchonthecode.com/tutorials/printing-in-wpf

        2
  •  0
  •   Drew Marsh    17 年前

    退房 the PrintDialog class . 你只需要打个电话 the PrintVisual method 路过 Image 作为具有您的 BitmapImage

    您可能希望设置其他打印选项,但在探索PrintDialog和相关API时会发现这些选项。

        3
  •  0
  •   schorsch1989    6 年前

    不合逻辑的回答有一个问题,那就是总是把图像拉伸到页面大小,并在尝试时切断一些内容。


    因此,我写了一个自己的解决方案,如果图像太大,只有拉伸(这是正确的词吗?)可以使用多个副本和页面方向。

    这是你的电话号码 Code