打印WPF BitmapImage的 [英] Printing a WPF BitmapImage

查看:500
本文介绍了打印WPF BitmapImage的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是打印的BitmapImage的最好方法是什么?我来自于System.Drawing中一个背景,所以我想将其转换为位图,然后打印出来,但我想有可能是一个更好的办法。

What's the best way to print a BitmapImage? I come from a background in System.Drawing so I was thinking about converting it to a Bitmap and then printing it, but I'm thinking there's probably a better way.

谢谢!

推荐答案

在德鲁的答案大厦,这是最好的衡量,并安排被交给PrintVisu​​al方法的容器。这将prevent的图像比从被切断一个8.5×11张纸上变大。下面是我的打印方式,这是部分可见图像的例子在屏幕上:

Building upon Drew's answer, it is best to measure and arrange the container that is handed to the PrintVisual method. This will prevent an image that is larger than a 8.5 x 11 sheet of paper from being cut off. Here is an example of how I printed an image that was partially visible on-screen:

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");
}

图像浏览在我的例子,可以与任何UIElement的容器代替,例如一个StackPanel上,帆布,网格,等。 ImageViewer.Source应设置为所述的BitmapImage即准备好进行打印。

ImageViewer in my example could be replaced with any UIElement container such as a stackpanel, canvas, grid, ect. ImageViewer.Source should be set to the BitmapImage that is ready to be printed.

我从这个网页的想法: HTTP://www.switchonthe$c$c.com/tutorials/printing -in-WPF

I got the idea from this page: http://www.switchonthecode.com/tutorials/printing-in-wpf

这篇关于打印WPF BitmapImage的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆