ESC指令打印图片


            Bitmap bmp = bmp = new Bitmap(500, 500);

            Graphics g = Graphics.FromImage(bmp);

            g.FillRectangle(Brushes.White, 0, 0, 580, 580);

            Font f1 = new Font("黑体", 16, FontStyle.Regular);

            g.DrawString("3941310", f1, Brushes.Black, 400, 0, new StringFormat());
            g.DrawString("028208", f1, Brushes.Black, 400,20, new StringFormat());

            pictureBox1.Image = bmp;

            
            int escType = 1;
            byte[] data = new byte[] { 0x1B, 0x33, 0x00 };
            lc.Write(data);
            data[0] = (byte)'\x00';
            data[1] = (byte)'\x00';
            data[2] = (byte)'\x00';    // Clear to Zero.

            Color pixelColor;

            // ESC * m nL nH
            byte[] escBmp = new byte[] { 0x1B, 0x2A, 0x00, 0x00, 0x00 };

            escBmp[2] = (byte)'\x21';
            escType = 3;

            //nL, nH
            escBmp[3] = (byte)(bmp.Width % 256);
            escBmp[4] = (byte)(bmp.Width / 256);


            // data
            for (int i = 0; i < (bmp.Height / 24) + 1; i++)
            {
                lc.Write(escBmp);

                for (int j = 0; j < bmp.Width; j++)
                {
                    for (int k = 0; k < 24; k++)
                    {
                        if (((i * 24) + k) < bmp.Height)   // if within the BMP size
                        {
                            pixelColor = bmp.GetPixel(j, (i * 24) + k);
                            if (pixelColor.R == 0)
                            {
                                data[k / 8] += (byte)(128 >> (k % 8));
                            }
                        }
                    }

                    lc.Write(data);
                    data[0] = (byte)'\x00';
                    data[1] = (byte)'\x00';
                    data[2] = (byte)'\x00';    // Clear to Zero.
                }

                lc.Write("\n");
            } // data

            //lc.Write("\n完成<GS *>方式的位图下载!\n");

            lc.Write(cutPaper);

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值