打印绘制对象 [英] Printing Drawn Object
问题描述
我有窗体。在表单画布上,我正在绘制多个矩形和线条。
我想要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 isSystem.Windows.Forms
, you can use the classSystem.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 ofSystem.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 (overriddenSystem.Windows.Forms.Control.OnPaint
or your handler of the eventSystem.Windows.Forms.Control.Paint
), with the printer''s instance ofGraphics
when usingPrintDocument
, with the bitmap instance ofGraphics
when writing drawing on a bitmap, for example, to provide export of graphics to a bitmap, and elsewhere.
—SA
这篇关于打印绘制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!