打印位图图像的最佳方法是什么?我有 System.Drawing 背景,所以我正在考虑将其转换为位图,然后打印它,但我认为可能有更好的方法。
Thanks!
根据 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 容器,例如 stackpanel、canvas、grid 等。 ImageViewer.Source 应设置为准备打印的 BitmapImage。
我从这个页面得到了这个想法:http://www.switchonthecode.com/tutorials/printing-in-wpf http://www.switchonthecode.com/tutorials/printing-in-wpf
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)