1IPAddress IP = ipaddress.parse ("192.168.1.212");2IPEndPoint Iport =NewIPEndPoint (IP,9100);//9100 specifying ports for small ticket printers3Socket SOC =Newsockets (AddressFamily.InterNetwork, SocketType.Stream, protocoltype.tcp);4 Soc. Connect (iport);5Bitmap =NewBitmap (@"D:\300X200.bmp");6 Soc. Send (Bmptobyte (bitmap));7Soc. Close ();
1 Public Static byte[] bmptobyte (Bitmap bmp)2 {3 inth = BMP. Height/ -+1;4 intW =bmp. Width;5 byte[] All =New byte[2+2* H + H *W] [];6 7all[0] =New byte[] {0x1B,0x33,0x00 };8 9 Color Pixelcolor;Ten //ESC * M NL nH bitmap One byte[] Escbmp =New byte[] {0x1B,0x2A,0x21, (byte) (w% the), (byte) (w/ the) }; A - //print on each line - for(inti =0; I < H; i++) the { -All[i * (W +2) +1] =escbmp; - for(intj =0; J < W; J + +) - { + byte[] data =New byte[] {0x00,0x00,0x00 }; - for(intK =0; K < -; k++) + { A if(((I * -) + K) <bmp. Height) at { -Pixelcolor = BMP. GetPixel (J, (I * -) +k); - if(PIXELCOLOR.R = =0) - { -Data[k/8] += (byte)( ->> (k%8)); - } in } - } toAll[i * (W +2) + j +2] =data; + } - //line Break theall[(i +1) * (W +2)] = Printercmdutils.nextline (1); * } $All[h * (W +2) +1] = Printercmdutils.nextline (2);Panax Notoginseng - returnBytemerger (all); the}
1 Public Static byte[] Bytemerger (byte[] bytelist)2 {3 intLength =0;4 for(inti =0; i < bytelist.length; i++)5 {6Length + =Bytelist[i]. Length;7 }8 byte[] result =New byte[Length];9 Ten intindex =0; One for(inti =0; i < bytelist.length; i++) A { - byte[] Nowbyte =Bytelist[i]; - for(intK =0; K < Bytelist[i]. Length; k++) the { -Result[index] =Nowbyte[k]; -index++; - } + } - returnresult; +}
Transferred from: http://www.cnblogs.com/rinack/p/4838963.html
C # Thermal Printer Socket network link print picture (ii)