问题
Maybe someone can help me with my Zebra ZPL problem. The ZPL manual doesn't really help me. I want to transfer binary (with ZPL B64) and compressed binary (with ZPL Z64) image data to the printer.
I was able to find the following information:
- with B64 the data is encoded in Base64 format.
- with Z64 the data is first compressed with LZ77 and then encoded with Base64.
- A CRC digit is appended to both encodings. (must probably be CRC-16) But I don't get a valid CRC check digit calculated!
Has any of you done that yet?
- With which parameters is the LZ77 algorithm used?
- Which CRC is used and with which start polynomial?
- Maybe someone even has a C# code for this problem?
Thank you very much.
回答1:
The ZPL manual doesn't really help me.
Tell me about it!
- The "LZ77" algorithm mentioned in the manual is in fact the ZLIB format. I used http://zlib.net for that.
The "CRC" mentioned in the manual is in fact CRC16-CCITT. Code I used: http://sanity-free.com/133/crc_16_ccitt_in_csharp.html.
In order to properly calculate it:
- Compress the picture bits using ZLIB (the picture must be
PixelFormat.Format1bppIndexed
, and the picture bits are best accessed with Bitmap.LockBits). - Encode the compressed data into Base64. No whitespace or line breaks allowed.
- Convert the Base64 string to a byte array according to ASCII encoding (
System.Text.Encoding.ASCII.GetBytes(base64string)
). - Calculate the CRC over that byte array. The Initial CRC Value must be zero.
- Compress the picture bits using ZLIB (the picture must be
来源:https://stackoverflow.com/questions/59319970/zpl-binary-b64-and-compressed-z64-encoding