将图像打印到Zebra iMZ320

时间:2016-05-18 20:12:32

标签: c# bitmap zebra-printers windows-mobile-6.5

平台:Windows Mobile 6.5掌上电脑

语言:C#

我的问题:我被要求从用户处捕获签名,然后将该签名发送到打印机以在收据上打印。我已经成功捕获了签名的图像,并在内存中具有签名的字节数组,但似乎无法正确打印。

为了让我开始,我按照blog here来获取位图的十六进制表示。但是,这只是用十六进制打印出一张很长的收据 签名的表示。这里的代码而不是链接:

    struct image * image_init( int w, int h) {
        struct image *img = malloc(sizeof(struct image));
        img->w = w;
        img->h = h;
        return img;
    }
...  
    struct image *img = image_init(100,100);

在失败之后,我找到了Zebra打印机的CPCL programming guide并按照第95页上的示例打印了小平铺图像。然而,这与签名完全相同。一旦失败,我发现在执行任何EG命令之前我需要运行命令:void image_init(struct image* img, int w, int h) { img->w = w; img->h = h; } ;所以我继续前进并做了这件事,但事情发生了变化,最终迫使我完全重置打印机和/或干净启动掌上电脑,因为它导致COM异常崩溃COM6和打印机。

我已经筋疲力尽了,如果不是所有我能想到的资源都没用,而且没有一个有效。

有没有人有任何其他想法或例子可以帮我搞定这个?

由于

1 个答案:

答案 0 :(得分:1)

我找到了另一个CPCL程序员指南,它有这个简单的(测试)示例:

! 0 200 200 210 1
EG 2 16 90 45 F0F0F0F0F0F0F0F00F0F0F0F0F0F0F0F
F0F0F0F0F0F0F0F00F0F0F0F0F0F0F0F
FORM
PRINT

这应该打印一个小的棋盘图案。

下一个示例打印PCX图形:

PCX Commands
The PCX command gives a user the ability to send “.PCX” graphics formatted images to the printer. The
.PCX image MUST be encoded as a black and white image.
Format:
{command} {x} {y}
{data}
where:
{command}: PCX
{x}: X-coordinate of the top-left corner.
{y}: Y-coordinate of the top-left corner.
{data}: PCX image data.

示例:

! 0 200 200 500 1
PCX 0 30
<binary black and white pcx data stream>
FORM
PRINT

使用文件的示例(先前已加载打印机文件系统)

! 0 200 200 500 1
PCX 0 30 !<IMAGE.PCX
FORM
PRINT

如果打印机已切换到行式打印机模式,则执行命令

! U1 PCX {x coordinate} {y coordinate} !< {filename.pcx}

例如

! U1 PCX 0 30 !< IMAGE.PCX

可用于从文件系统打印单色PCX。

记住.NET是UTF-8,所以在通过COM端口发送之前,所有命令和数据都必须转换为ASCII。所以做这样的事情:

        Encoding ansi = Encoding.GetEncoding(1252);
        byte[] buf = ansi.GetBytes(DataString);
        System.IO.Ports.SerialPort sp = new System.IO.Ports.SerialPort("COM1:");
        sp.Write(buf, 0, buf.Length);

对于PCX数据,只需使用字节流作为byte []缓冲区。