Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

escpos - ESC POS command ESC* for printing bit image on printer

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 . 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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...