e.图形可以默认尺寸打印 [英] e.Graphics can print in default size

查看:107
本文介绍了e.图形可以默认尺寸打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个可以打印一些图形的APP中工作,不同的尺寸我们拥有3种不同型号的打印机和CutePDF打印机.

如果我使用此代码打印图像

i''m working in one APP that print some Drawings, diferent sizes we hace 3 diferent models of printers and CutePDF Printer.

if i print my image with this code

Dim im As Image
im = Image.FromFile("C:\Image.jpg")
Dim p As New PointF(0, 3)
e.Graphics.DrawImage(im, p)
e.Graphics.DrawString("Copy", New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 3, 0)



使用CUTEPDF图像可以很好地打印
但是如果我将图像发送到我们的一台打印机,它就不能全部显示在页面上.

我的问题是:

使用e.Graphics,我可以发送具有默认尺寸或适合页面大小的图像吗?
使用e.Graphics,我无法将图像自动调整为打印机默认的DPI吗?

谢谢.



with the CUTEPDF The image is printed fine
but if i send the image to one of our printers, it doesnt fit all at page.

My questions are:

With e.Graphics i can send images with default size or fit to the page?
With e.Graphics i cant autoajust the image to the printer default DPI?

Thank you.

推荐答案

请参阅我对问题的评论,下次,请确保您提供了足够的信息.

现在,从逻辑上进行思考:您要么需要知道页面可打印区域的像素大小,要么需要知道以英寸+ DPI(每英寸的点数)为单位的大小,而不是两者都知道,因为这两个变量相互依赖,如果全部使用它们会产生矛盾.在这种情况下,您将获得以像素为单位的可打印区域.打印页面时,它会在事件参数中给出;此值为System.Drawing.Printing.PrintPageEventArgs.MarginBounds:
http://msdn.microsoft.com/en-us/library/system. drawing.printing.printpageeventargs.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.marginbounds.aspx [ ^ ].

在事件System.Drawing.Printing.PrintDocument.PrintPage的处理程序中打印页面时,将获得此参数:
http://msdn.microsoft.com/en-us/library/system. drawing.printing.printdocument.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx [ ^ ].

在上面引用的最后两篇文章中,有简短的代码示例.如果您正在做其他事情,那么您做错了.同样,太糟糕了,您没有显示代码的基本上下文.

我还建议您开发一种用于呈现某些控件,表单或表单的一部分以在屏幕和打印页面上呈现的单一方法,并将相关参数传递给该方法.您可以这样做,因为在两种情况下,您都在处理System.Drawing.Graphics的实例:
http://msdn.microsoft.com/en-us/library/system.drawing. graphics.aspx [^ ].

此外,您可以传递边距和/或其他相关参数.这将使您的打印与屏幕上的渲染保持一致,并帮助您避免重复代码.

—SA
Please see my comment to the question and, next time, make sure you provide enough information.

Now, think logically: you either need to know pixel size of the printable area of the page or size in inches + DPI (dots per inch), not both, because these variables depend on each other and can contradict if you take them all. In this case, you are given the printable area in pixels; it is given you in the event arguments when you print a page; this value is System.Drawing.Printing.PrintPageEventArgs.MarginBounds:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.marginbounds.aspx[^].

You get this parameters when you print a page in your handler of the of event System.Drawing.Printing.PrintDocument.PrintPage:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx[^].

In the two last articles referenced above, there are short code samples. If you are doing something else, you are doing it wrong. Again, too bad you did not show essential context of your code.

I would also advice that you develop a single method for rendering some control, form or part of it for rendering on both screen and print page, and pass relevant parameters to this method. You can do it, because in both cases you are dealing with the instance of System.Drawing.Graphics:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

Additionally, you can pass margin and/or other relevant parameters. This will make your printing consistent with on-screen rendering and will help you to avoid repeating of code.

—SA


这篇关于e.图形可以默认尺寸打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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