如何将printdocument对象转换为位图图像 [英] How to convert printdocument object to bitmap image

查看:317
本文介绍了如何将printdocument对象转换为位图图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个自定义打印预览控件,我将更改打印文档,并希望查看文档的动态渲染图像,即如果发送到打印机将打印的已更改文档。

但我不知道如何将文档呈现到图像列表(1图像/页)。



我已经搜索了现成的解决方案&发现了这个。



http://stackoverflow.com/questions/10868623/converting-print-page-graphics-to-bitmap-c-sharp



提前致谢。



我的尝试:



没什么特别的。我不知道如何将printdocument对象渲染为位图:(

I want to create a custom print preview contol like thing in which I shall change the print document and want to see the dynamicaly rendered image of the document i.e. changed document that will be printed if sent to printer.
But I donot have any idea about how to render the document to image list (1 image/page).

I have searched for ready made solutions & found this.

http://stackoverflow.com/questions/10868623/converting-print-page-graphics-to-bitmap-c-sharp

Thanks in advance.

What I have tried:

Nothing special. I have no idea how to render printdocument object to bitmap :(

推荐答案

它实际上很简单。你的打印例程有一个你通常打印的Graphics对象将输出发送到打印机时,将从打印机的设备上下文创建此Graphics对象 - 从而将输出发送到打印机。



如果创建位图然后,您可以使用白色背景和与打印机页面相同的大小,从该位图创建一个Graphics对象。如果将该Graphics对象传递给打印例程,它们将打印到您的位图而不是打印机。创建一个新的每个打印机页面的位图,调整它们以适合您的预览窗口,然后你去 - 完成所有。
Its actually quite simple to do. Your "Print" routines have a Graphics object that you normally print to. When sending the output to the printer, this Graphics object is created from the printer's device context - thus sending the output to the printer.

If you create a bitmap with a white background and the same size as your printer page, you can then create a Graphics object from that bitmap. If you pass that Graphics object to the print routines, then they will print onto your bitmap instead of the printer. Create a new bitmap for each printer page, resize them to fit into your preview window, and there you go - all done.


这篇关于如何将printdocument对象转换为位图图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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