ESC POS command ESC* for printing bit image on printer

爷,独闯天下 提交于 2020-01-11 03:56:05

问题


I want to print a bitmap logo file with ESC POS command ESC*. Following is the link for technical documentation of the command.

https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=88

According to me, the printer requires the image data in the form of 1s and 0s. So, it prints a dot, with the occurrence of 1 and blank, with the occurrence of 0. But I am not able to figure out how to send multi line bit image data with the help of above command, since the command accepts only the image data in the horizontal direction. Please help me with the problem.


回答1:


ESC * is one of several "bit image" commands in ESC/POS. It accepts "column format" data, which can only represent a single line of either 8 or 24 pixels. So there are two good options here.

Print multiple lines using ESC *

It sounds like you are able to print one line, so I will assume that the data format itself is not an issue.

You can print multiple lines by simply repeating the command to print the extra lines, separated by line breaks \n. This requires chopping up the image, and padding it with whitespace so that it is a multiple of 8 or 24 pixels in height (again, due to the format).

Because of line spacing, you need to issue a command to change the size of line feeds during the image print, then another command to reset them at the end.

I use ESC 3 0x10 for 16-unit line feeds (bytes 0x1b 0x33 0x10) and ESC 2 (bytes 0x1b 0x32) to reset.

  • Example of column format bit image printing in Python using ESC *
  • Example of column format bit image printing in PHP using ESC *

This method of printing has excellent compatibility with old printers, but you can get some thin horizontal lines in the output.

Print the entire image with GS v 0

This bit image command accepts the different "raster format" data. I make use of the fact that the blob in this format is identical to the binary data in the widely implemented PBM bitmap format (specifically the binary data in files with the P4 header).

The height of the image will be limited by your print buffer size, but could go up to 65535 pixels. The width must be divisible by 8 because of the representation.

  • Example of raster format bit image printing in Python using VS v 0
  • Example of raster format bit image printing in PHP using GS v 0

Side note: These snippets the actual prototypes of the image processing code that now appears in the popular open source escpos-php and python-escpos libraries. Using an existing library has a number of benefits, and you should consider it if it's an option.



来源:https://stackoverflow.com/questions/44107254/esc-pos-command-esc-for-printing-bit-image-on-printer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!