问题
i have an Epson-TMH6000III thermal printer and i want to print some bitmap with it by using ESC/POS commands.
but before this i want to print a very simple single line with ESC/POS printing image commands.
here's my attempt :
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.
回答1:
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 ..>
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 *
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)
And the meaning of these bytes is:
GS v 0 <density byte> <4 bytes image size data> <1 byte data>
回答2:
Probably too late to be useful for the initial question, but for future reference, as I've been searching myself quite a lot before finding how to send bit images to a printer using POS.
Among the several options, it seems that the easiest one is using the "ESC*0" command followed by the number of bytes (2 bytes, high and low), the actual data and then a "\n".
All the details / specs for the command are in the manual if you search for "ESC * Select bit image", but knowing that this option exists and it's relatively simple and fast is really the tricky bit...
You can also find a concrete code example, in Haskell and some more details on this post.
来源:https://stackoverflow.com/questions/36952668/how-to-print-images-with-esc-pos-commands