小智 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");
}
Run Code Online (Sandbox Code Playgroud)
我的示例中的ImageViewer可以替换为任何UIElement容器,例如stackpanel,canvas,grid等.应将ImageViewer.Source设置为可以打印的BitmapImage.
我从这个页面得到了这个想法:http: //www.switchonthecode.com/tutorials/printing-in-wpf
| 归档时间: |
|
| 查看次数: |
5699 次 |
| 最近记录: |