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指令打印图片
最新推荐文章于 2024-06-21 09:44:40 发布