从控制台应用程序打印图片 [英] Printing a picture from a Console Application

查看:68
本文介绍了从控制台应用程序打印图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到如何在 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 应用程序来进行打印.只需使用 PrintDocumentDrawImage 类,您可以执行以下操作:

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)

这篇关于从控制台应用程序打印图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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