C # Thermal Printer Socket network link print picture (ii)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.