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)
.