[英]Printing a WPF BitmapImage
打印 BitmapImage 的最佳方法是什么? 我來自 System.Drawing 的背景,所以我正在考慮將其轉換為位圖然后打印它,但我認為可能有更好的方法。
謝謝!
根據 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
查看PrintDialog
類。 您需要做的就是調用PrintVisual
方法,傳入一個Image
作為視覺對象,並將您的BitmapImage
作為源。
您可能想要設置其他打印選項,但您會在探索 PrintDialog 和相關 API 時發現這些選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.