http://blog.csdn.net/sdvch/article/details/45079375
最近研究热敏打印机打印二维码,用到了北洋OPOS二次开发包DLL,借鉴该代码:http://www.cnblogs.com/datacool/archive/2012/11/27/2014666.html ,下面是扩展的一个打印图片的方法
/// <summary> /// 打印图片 /// </summary> /// <param name="bmp"></param> public void PrintBmp(Bitmap bmp) { byte[] data = new byte[] { 0x1B, 0x33, 0x00 }; POS_WriteFile(POS_IntPtr, data, (uint)data.Length); data[0] = (byte)'x00'; data[1] = (byte)'x00'; data[2] = (byte)'x00'; // Clear to Zero. Color pixelColor; //ESC * m nL nH d1…dk 选择位图模式 // ESC * m nL nH byte[] escBmp = new byte[] { 0x1B, 0x2A, 0x00, 0x00, 0x00 }; escBmp[2] = (byte)'x21'; //nL, nH escBmp[3] = (byte)(bmp.Width % 256); escBmp[4] = (byte)(bmp.Width / 256); //循环图片像素打印图片 //循环高 for (int i = 0; i < (bmp.Height / 24 + 1); i++) { //设置模式为位图模式 POS_WriteFile(POS_IntPtr, escBmp, (uint)escBmp.Length); //循环宽 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)); } } } //一次写入一个data,24个像素 POS_WriteFile(POS_IntPtr, data, (uint)data.Length); data[0] = (byte)'x00'; data[1] = (byte)'x00'; data[2] = (byte)'x00'; // Clear to Zero. } //换行,打印第二行 byte[] data2 = { 0xA }; POS_WriteFile(POS_IntPtr, data2, (uint)data2.Length); } // data byte[] data3 = { 0xA, 0xA }; POS_WriteFile(POS_IntPtr, data3, (uint)data3.Length);