Image (PCX) for EPL2 Zebra printer

五迷三道 提交于 2019-12-01 13:09:36

Here's the way I found to create the PCX properly:

In gimp, save the file as a 1-bit (black and white) BMP. Don't select PCX because the saved format is not 1-bit PCX as required by the printer!

Use imagemagick's convert program to convert your BMP to PCX.

The other issue I ran across after I got that down was that graphics were still corrupt, that was a codepage issue, so watch out for that.

You don't mention which programming language you're using.

If it's C# (or .NET in general), then here's a blog post about printing images with EPL:
Using the EPL2 GW command to send an image to a Zebra thermal printer

And another blog post from the same guy, that got me started with printing EPL to Zebra printers with C#.

There're two ways to output PCX graphics using EPL2 language. The first one is the one you suggested:

GK"namepcx"
GK"namepcx"
GM"namepcx",3042
..... and here follows monochrome PCX data ...
..... with 128-bit header and following pixel data 1 bit-per pixel..

later you should be able to write this stored "namepcx" to printer's image buffer via GM however I spent two days trying store PCX, but it would never be stored correctly. So I ended up simply using GW command to write pixel data directly to the printers image buffer. Avoiding "storing in flash memory". Also originally this "flash" storage via GM was meant to store some image (like logo) which would repeat on all labels. Thus you may store it once and then print 10 000 labels with the same logo. However if priting from java, usually you would be printing many different images on different labels. Thus if you store to flash new image for every label, then you will "wear off" flash memory really quickly. (Eg. manual for LP 2824 printer says that flash memory only has 100k write cycles).

So it may seem that using GW to write imag directly to image buffer instead of using 3-step GK GM GG may be a better solution.

Disclaimer: I am currently writing a SVG-to-EPL-transpiler, which can be found here

I was facing the same issue lately, and solved it with sending a GW-command to the printer.

The main difference to GK-GK-GM-GG is that you don't send the PCX-header along, but rather the raw binary data (afaik without LRE compression).

I used following (non-optimized/naive) C# code, which heavily uses bit-shifting. The algorithm can be implemented in any language though and is straightforward:

[NotNull]
public IEnumerable<byte> GetRawBinaryData([NotNull] Bitmap bitmap,
                                          int octetts)
{
  var height = bitmap.Height;
  var width = bitmap.Width;

  for (var y = 0;
        y < height;
        y++)
  {
    for (var octett = 0;
          octett < octetts;
          octett++)
    {
      var value = (int) byte.MaxValue;

      for (var i = 0;
            i < 8;
            i++)
      {
        var x = octett * 8 + i;
        var bitIndex = 7 - i;
        if (x < width)
        {
          var color = bitmap.GetPixel(x,
                                      y);
          if (color.A > 0x32
              || color.R > 0x96 && color.G > 0x96 && color.B > 0x96)
          {
            value &= ~(1 << bitIndex);
          }
        }
      }

      yield return (byte) value;
    }
  }
}

The thing you have to keep in mind for conversions:

  • 1: white dot
  • 0: black dot
  • width has to be a multiple of 8 (as we are sending bytes) - the code above takes care of this by padding
  • rotation/orientation of the label!
  • some threshold is implemented here ...

I have also implemented GM-GG, but this would go beyond the scope of this answer. The relevant code can be found in EplCommands.StoreGraphics(bitmap:Bitmap,name:string).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!