我是靠谱客的博主 等待白开水,这篇文章主要介绍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);

最后

以上就是等待白开水最近收集整理的关于ESC指令打印图片的全部内容,更多相关ESC指令打印图片内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(115)

评论列表共有 0 条评论

立即
投稿
返回
顶部