打印PNG图像斑马网络打印机 [英] Printing PNG images to a zebra network printer

查看:825
本文介绍了打印PNG图像斑马网络打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到图像打印到斑马和有很多麻烦的一种方式。

I am trying to find a way of printing images to a zebra and having a lot of trouble.

根据文档:

第一个编码,被称为B64,EN codeS中的数据使用MIME
  Base64编码方案。 Base64是用来连接code电子邮件atachedments ...

  Base64编码的连接codeS六位的字节,对于33%的expantion
  在未封闭的数据。
第二个编码,被称为Z64,
  第一个COM presses用LZ77算法来减少其大小的数据。
  (该算法所使用的PKZIP及为整体的PNG
  图形格式。)
使用的COM pressed数据然后连接codeD
  如上所述MIME Base64编码方案。
的CRC将被计算
  翻过为Base64恩codeD数据。

The first encoding, known as B64, encodes the data using the MIME Base64 scheme. Base64 is used to encode e-mail atachedments ...
Base64 encodes six bits to the byte, for an expantion of 33 percent over the un-enclosed data.
The second encoding, known as Z64, first compresses the data using the LZ77 algorithm to reduce its size. (This algorithm is used by the PKZIP and is intergral to the PNG graphics format.)
The compressed data is then encoded using the MIME Base64 scheme as described above.
A CRC will be calculated accross the Base64-encoded data.

不过,这并不有一个很大的更多信息。

But it doesn't have a great deal more info.

基本上我试图用编码

private byte[] GetItemFromPath(string filepath)
{   
    using (MemoryStream ms = new MemoryStream())
    {
        using (Image img = Image.FromFile(filepath))
        {
            img.Save(ms, ImageFormat.Png);
            return ms.ToArray();
        }
    }
}

然后试图用类似打印:

Then trying to print with something like:

var initialArray = GetItemFromPath("C:\\RED.png");
string converted = Convert.ToBase64String(b);

PrintThis(string.Format(@"~DYRED.PNG,P,P,{1},0,:B64:
{0}
^XA
^F0200,200^XGRED.PNG,1,1^FS
^XZ", converted .ToString(), initialArray.Length));

从它的声音,无论是B64或Z64都接受了。

From the sounds of it, either B64 or Z64 are both accepted.

我已经尝试了一些变化,和几个生成的CRC和计算'大小'的方法。
但没有似乎工作和图形的打印机的下载总是得到中止。

I've tried a few variations, and a couple of methods for generating the CRC and calculating the 'size'. But none seem to work and the download of the graphics to the printer is always getting aborted.

有没有人成功地完成这样的事情?或者知道我要去的地方错了?

Has anyone managed to accomplish something like this? Or knows where I am going wrong?

推荐答案

所有信用卡,我来到这个答案是从<一个href=\"http://forums.ni.com/t5/LabVIEW/Convert-jpg-to-ASCII-for-Zebra-printer-ZPL-$c$c-output/td-p/2472898\">LabView论坛用户Raydur。他职位,可以在LabVIEW开辟发送图像下来LabView的解决方案。我个人并没有与我的打印机运行它,我只是用它来找出正确的图像code,所以我可以在我的code复制它。我缺少的是填充我的十六进制值code中的一件大事。例如:1A是好的,但如果你只是一个,你需要垫0在它前面发送0A。在您发送的ZPL文件的大小也是字节数组的原始尺寸,而不是最后一个字符串重数据presentation。

All credit for me coming to this answer was from LabView Forum user Raydur. He posts a LabView solution that can be opened up in LabView to send images down. I personally didn't run it with my printer, I just used it to figure out the correct image code so I could replicate it in my code. The big thing that I was missing was padding my Hexadecimal code. For example: 1A is fine, but if you have just A, you need to pad a 0 in front of it to send 0A. The size of the file in the ZPL you are sending is also the original size of the byte array, not the final string representation of the data.

我已经冲刷了很多很多,很多论坛和帖子#1试图弄清楚这一点,因为它似乎是这样一个简单的事情。我已经尝试了各种单一的解决方案张贴在其他地方,但我真的想只是打印。PNG,因为我的打印机(移动QLN320)的手册中有支持它内置的。它说,要么把它以Base64或十六进制,我试着既无济于事。对于任何想要做的Base64,我在您需要手动计算CRC codeS因为我选择去与十六进制更容易路线要找这么每个数据包一个旧的手册中。因此,这里是code我有工作了!

I've scoured many, many, many forums and Stackoverflow posts trying to figure this out because it seems like such a simple thing to do. I've tried every single solution posted elsewhere but I really wanted to just print a .PNG because the manual for my printer(Mobile QLN320) has support for it built in. It says to either send it in Base64 or Hexadecimal, and I tried both to no avail. For anyone wanting to do Base64, I found in a older manual that you need to manually calculate CRC codes for each packet you send so I chose to go with the easier Hexadecimal route. So here is the code I got to work!

        string ipAddress = "192.168.1.30";
        int port = 6101;

        string zplImageData = string.Empty;
        //Make sure no transparency exists. I had some trouble with this. This PNG has a white background
        string filePath = @"C:\Users\Path\To\Logo.png";
        byte[] binaryData = System.IO.File.ReadAllBytes(filePath);
        foreach (Byte b in binaryData)
        {
            string hexRep = String.Format("{0:X}", b);
            if (hexRep.Length == 1)
                hexRep = "0" + hexRep;
            zplImageData += hexRep;
          }
          string zplToSend = "^XA" + "^MNN" + "^LL500" + "~DYE:LOGO,P,P," + binaryData.Length + ",," + zplImageData+"^XZ";
          string printImage = "^XA^FO115,50^IME:LOGO.PNG^FS^XZ";

        try
        {
            // Open connection
            System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
            client.Connect(ipAddress, port);

            // Write ZPL String to connection
            System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream(),Encoding.UTF8);
            writer.Write(zplToSend);
            writer.Flush();
            writer.Write(printImage);
            writer.Flush();
            // Close Connection
            writer.Close();
            client.Close();
        }
        catch (Exception ex)
        {
            // Catch Exception
        }

这篇关于打印PNG图像斑马网络打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆