从控制台应用程序打印图片
我试图找到如何在 C# 中打印图片(如在纸上).我试图保持它非常简单.所以不使用 WinForms,只使用控制台输出.
I am trying to find how to print a picture (as in on paper) in C#. I'm trying to keep it very simple. So no use of WinForms and just using Console output.
我自己寻找答案,但无法理解任何结果.
I looked for an answer myself, but couldn't make sense of any of the results.
您不一定需要 WinForm 应用程序来进行打印.只需使用 PrintDocument 和 DrawImage 类,您可以执行以下操作:
You necessarily don't need a WinForm application to do printing. JUst use PrintDocument and DrawImage class and you can do somthing like this:
PrintDocument pd = new PrintDocument();
pd.PrintPage += (thesender, ev) => {
ev.Graphics.DrawImage(Image.FromFile("Your Image Path"),
//This is to keep image in margins of the Page.
new PointF(ev.MarginBounds.Left,ev.MarginBounds.Top));
};
pd.Print();
希望有所帮助.(我已经使用Lambada和匿名代表处理事件,如果你不明白,请告诉我将发布普通版本)
Hope that Helps. (I have used Lambada and Anonymous Delegate to handle the Event, I f you dont understand that please tell i will post the normal version)