C# 使用POS命令C的ASCII转换将图形打印到Epson打印机#

C# 使用POS命令C的ASCII转换将图形打印到Epson打印机#,c#,printing,byte,ascii,epson,C#,Printing,Byte,Ascii,Epson,一直在尝试使用C#和RawPrinterHelper类打印到我的EPSON TM-T88IIIP打印机,到目前为止,我只能打印文本,现在我需要的是打印图形,但EPSON文档对此并不清楚 这是我打印文本的代码: static string printerName = "Epson TM-T88III"; static string ESC = Convert.ToString((char)27); static string LF = Convert.ToString((c

一直在尝试使用C#和RawPrinterHelper类打印到我的EPSON TM-T88IIIP打印机,到目前为止,我只能打印文本,现在我需要的是打印图形,但EPSON文档对此并不清楚

这是我打印文本的代码:

    static string printerName = "Epson TM-T88III";
    static string ESC = Convert.ToString((char)27);
    static string LF = Convert.ToString((char)10);
    static string GS = Convert.ToString((char)29);
    static string cutCommand = $"{ESC}@{GS}V{(char)66}{(char)0}";

    static void Main(string[] args)
    {
        PrintText();
        //PrintGraphics();
    }

    private static void PrintText()
    {                        
        byte[] bytes = Encoding.Unicode.GetBytes($@"{ESC}COMPANYNAME.{LF}COMPANY ADDRESS{LF}RANDOM TEXT{LF}__________________________________________{LF}{(char)179}1234567890123456789012345678901234567890{(char)179}{LF}{(char)196}{LF}");
        RawPrinterHelper.SendBytesToPrinter(printerName, bytes);
        RawPrinterHelper.SendBytesToPrinter(printerName, Encoding.ASCII.GetBytes(cutCommand));
    }

它工作得非常好,现在图形命令是这样的:

命令定义='//GS(L pL pH m fn a kc1/Kc2 b xL xH yL yH c

命令执行=GS“(L”139 7 48 67 48“G1”1 128 0 120 0 49

问题是,如何在ASCII中转义所有这些参数,我的代码到目前为止:

public static void PrintGraphics()
    {                        
        byte[] commandBytes = Encoding.ASCII.GetBytes($"{ESC}@{GS}{(char)40}{(char)76}{(char)139}{(char)7}{(char)48}{(char)67}{(char)48}G1{(char)1}{(char)128}{(char)0}{(char)120}{(char)0}{(char)49}");
        //byte[] commandBytes = Encoding.Unicode.GetBytes($"{ESC} (L 139 7 48 67 48 G1 1 128 0 120 0 49");
        byte[] imageBytes = Example.GetExampleImageBytes();
        byte[] commandEndBytes = Encoding.ASCII.GetBytes($"{ESC}@{GS}{(char)40}{(char)76}{(char)6}{(char)0}{(char)48}{(char)69}G1{(char)1}{(char)1}");
        byte[] endBytes = commandBytes.Concat(imageBytes).Concat(commandEndBytes).ToArray();
        RawPrinterHelper.SendBytesToPrinter(printerName, endBytes);
        RawPrinterHelper.SendBytesToPrinter(printerName, Encoding.ASCII.GetBytes(cutCommand));
    }

要打印图形,您需要知道“位图像”的文档含义以及数据的格式。命令列表中没有这些信息。我在这篇文章中找到了数据的格式,然后使用RawPrinter方法将字节发送到打印机