打印 WPF 位图图像
打印位图图像的最佳方法是什么?我有 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.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 Drew 的回答,最好测量并安排传递给 PrintVisual 方法的容器。这将防止大于 8.5 x 11 纸张的图像被剪掉。下面是我如何打印在屏幕上部分可见的图像的示例:
我的示例中的 ImageViewer 可以替换为任何 UIElement 容器,例如 stackpanel、canvas、grid 等。 ImageViewer.Source 应设置为准备打印的 BitmapImage。
我从这个页面得到了这个想法:
http://www.switchonthecode.com/tutorials/printing-in-wpf
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:
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.
I got the idea from this page:
http://www.switchonthecode.com/tutorials/printing-in-wpf
查看
PrintDialog
类。您需要做的就是调用 < code>PrintVisual 方法 传入Image
作为以BitmapImage
作为源的视觉对象。您可能想要设置其他打印选项,但是当您探索 PrintDialog 和相关 API 时您会发现这些选项。
Check out the
PrintDialog
class. All you should need to do is call thePrintVisual
method passing in anImage
as the visual that has yourBitmapImage
as a source.You may want to setup other printing options, but you'll discover those as you explore PrintDialog and related APIs.
不合逻辑的答案有问题,它总是将图像拉伸到页面大小并在尝试此操作时切断一些内容。
因此我写了一个自己的解决方案,只有拉伸(这是正确的词吗?)如果图像太大,可以使用多重副本和页面方向。
这是代码
illogial's answer has the problem, that's always stretching the image to pagesize and cuts off some content at trying this.
Therefore i wrote a own solution, which only stretch(is this the right word?) if the image is to large, can use multiply copies and pageorientations.
Here is the Code