C#打印图片

命名空间:

using System.Drawing.Printing;

实例化:

private PrintDocument pd = new PrintDocument();

打印事件(Tu是个Image对象):

 

     SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);
        Font DrawFont = new Font("Arial", 22);
        /// <summary>
        /// 打印事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PicturePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(Tu, 0, 0);  //img大小
            e.Graphics.DrawString(TicCode, DrawFont, brush, 600, 600); //绘制字符串
            e.HasMorePages = false;
        }

 

 

 

注册事件选择打印机然后打印:

pd.PrintPage += PicturePrintDocument_PrintPage; //注册打印事件
pd.PrinterSettings.PrinterName = "HP LaserJet Professional M1213nf MFP";        //打印机选择
pd.Print();    =>就似这么简单
 

 

posted @ 2017-07-27 17:01  XinYiBuFang  阅读(8209)  评论(0编辑  收藏  举报