打印绘制对象 [英] Printing Drawn Object

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

问题描述





我有窗体。在表单画布上,我正在绘制多个矩形和线条。

我想要suport sprint functionlity,它将打印画布上绘制的图像。



有一种替代方案

1.我们可以使用

 CopyFromScreen创建图像

然后添加到打印doucment并打印它。当我们创建.jpeg时,图像的质量不好,而且没有正确显示。



还有其他最好的选择,以确保显示质量将保持。 ?









谢谢。

解决方案

如果这是 System.Windows.Forms ,则可以使用类 System.Drawing.Printing.PrintDocument

http: //msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx [ ^ ]。



如果你想打印某些东西已经在屏幕上绘制的,你应该抽象出你的渲染方法,因为从 System.Drawing.Graphics 实例的性质中抽象出一些单独的方法,将这样的实例传递给参数,以及一些其他必需的参数,比如传递一个剪辑区域来绘制,或者可能是其他细节:



 <跨度cl ass =code-keyword> void 渲染(System.Drawing.Graphics图形,Rectangle drawingArea  / *   ,... * / ){
// 在此处绘制
}





这样,您就可以通过屏幕渲染方法调用相同的方法(覆盖 System.Windows.Forms.Control.OnPaint 或您的事件处理程序 System.Windows.Forms.Control.Paint ),带打印机使用 PrintDocument 时的 Graphics 的实例,位图实例 Graphics 在位图上绘图时,例如,提供图形导出到位图和其他地方。



-SA

Hi,

I have windows form. On form canvas, I am drawing muliple rectangles and lines.
I want so suport sprint functionlity, which will print images drawn on for canvas.

There is one alternative that
1.We can create image using

CopyFromScreen

and then add to print doucment and print it. When we create .jpeg the qulity of image is not good and which is not displayed properly.

Is there other best alternative which will make sure that display qulity will maintain. ?




Thanks.

解决方案

If this is System.Windows.Forms, you can use the class System.Drawing.Printing.PrintDocument:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

If you want to print something which is already drawn on screen, you should abstract out your rendering method as some separate method abstracted from the nature of the instance of System.Drawing.Graphics, passing such instance as a parameter, along with some other required parameters, say, to pass a clip region to draw in, or perhaps other detail:

void Render(System.Drawing.Graphics graphics, Rectangle drawingArea /* , ... */) {
   // draw here
}



This way, you will be able to call the same method from your screen rendering method (overridden System.Windows.Forms.Control.OnPaint or your handler of the event System.Windows.Forms.Control.Paint), with the printer''s instance of Graphics when using PrintDocument, with the bitmap instance of Graphics when writing drawing on a bitmap, for example, to provide export of graphics to a bitmap, and elsewhere.

—SA


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

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