如何使用ESC/POS命令打印图像? [英] how to print images with ESC/POS commands?
问题描述
我有一个Epson-TMH6000III热敏打印机,我想通过ESC/POS命令用它打印一些位图.
i have an Epson-TMH6000III thermal printer and i want to print some bitmap with it by using ESC/POS commands.
但是在此之前,我想使用ESC/POS打印图像命令来打印非常简单的一行.
but before this i want to print a very simple single line with ESC/POS printing image commands.
这是我的尝试:
namespace printingImageMode
{
class Program
{
static void Main(string[] args)
{
Bitmap bmp = new Bitmap(@"C:\Users\falamarzi\Desktop\Kyan Graphic Viewer\jTest.jpg");
int msb = (int)(bmp.Width & 0x0000ff00) >> 8;
int lsb = (int)(bmp.Width & 0x000000ff);
byte msbB = Convert.ToByte(msb);
byte lsbB = Convert.ToByte(lsb);
byte[] enter_To_Image_Printing_Mode_Command = new byte[] { (byte)AsciiControlChars.ESC, (byte)DensityCommand.EightDot_SD, msbB, lsbB };
byte[] imageData = new byte[lsb + msb * 256];
for (int i = 0; i < imageData.Length; i++)
{
imageData[i] = 0xff;
}
byte[] complete_Command = new byte[enter_To_Image_Printing_Mode_Command.Length + imageData.Length];
enter_To_Image_Printing_Mode_Command.CopyTo(complete_Command, 0);
imageData.CopyTo(complete_Command, enter_To_Image_Printing_Mode_Command.Length);
SerialPort sPort = new SerialPort("COM5");
sPort.Open();
sPort.Write(complete_Command, 0, complete_Command.Length);
}
}
public enum AsciiControlChars : byte
{
ESC = 0x1b,
}
public enum DensityCommand : byte
{
EightDot_SD = 0x00,
EightDot_DD = 0x01,
TwentyFourDot_SD = 0x20,
TwentyFourDot_DD = 0x21,
}
}
我没有得到结果.我对此表示感谢.
i didn't get the result. i appreciate for any help in this.
推荐答案
一个问题似乎是在数据之前放置的标题.如果我没看错,您正在发送:
One issue appears to be the header being placed before the data. If I am reading correctly, you are sending:
ESC <density byte> <size data> <data ..>
由于ESC本身不是图像打印命令,因此您需要调整实现以匹配ESC/POS图像打印命令.我将以您的实施接近完成状态为前提,您已经可以访问描述了这些命令的文档:
Because ESC is not itself an image print command, you will need to adjust your implementation to match an ESC/POS image print command. I will assume by the near-completeness of your implementation that you have access to documentation which describes these commands already:
GS v 0
GS ( L
ESC *
要检查实施情况,可以从项目 escpos-php 移植一些单元测试,或者 python-escpos ,两者均支持图像打印.
To check your implementation, you could port some unit tests from the projects escpos-php or python-escpos, both of which support image printing.
For example, the syntax to print a single black pixel via GS v 0
is (source):
\x1d v 0 \x00 \x01 \x00 \x01 \x00 \x80
(non-printable ASCII characters shown here as hex codes)
这些字节的含义是:
GS v 0 <density byte> <4 bytes image size data> <1 byte data>
这篇关于如何使用ESC/POS命令打印图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!