6

打印 BitmapImage 的最佳方法是什么?我来自 System.Drawing 的背景,所以我正在考虑将其转换为位图然后打印它,但我认为可能有更好的方法。

谢谢!

4

3 回答 3

5

根据 Drew 的回答,最好测量和安排交给 PrintVisual 方法的容器。这将防止大于 8.5 x 11 纸的图像被切掉。这是我如何打印在屏幕上部分可见的图像的示例:

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 容器,例如堆栈面板、画布、网格等。ImageViewer.Source 应设置为准备打印的 BitmapImage。

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

于 2009-11-03T16:23:50.210 回答
0

查看课程_ PrintDialog您需要做的就是调用以您为源的视觉对象传入PrintVisual方法。ImageBitmapImage

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

于 2009-11-02T16:24:40.357 回答
0

illogial 的答案有问题,总是将图像拉伸到页面大小并在尝试此操作时截断一些内容。


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

这是代码

于 2020-08-12T21:03:40.853 回答