斑马打印机打印图片

淺唱寂寞╮ 提交于 2019-12-07 18:29:54

斑马105SL打印机如何将图标生成固定的文件,然后调用呢?


发布时间: 2012-3-25 12:38:39

双击自动滚屏打印此页】【关闭本页

问题:

斑马105SL打印机用串口ZPL指令打印时,当打印一些图标时,需要发送很多的字符串,请问能否把这些图标生成一个固定的文件,这样以后只需发送相应的文件名就可打印相关的图标了。请赐教!

 

 

 

敏用数码解答:

 

斑马105SL实现这个功能是没有任何问题的,但需要注意105sl的内存配置,老型号的105sl采用4MB RAM(R:),2MB闪存(E:),新型号的105sl采用6MB RAM(R:),4MB闪存(E:)。避免条码打印机出现图形过大下载溢出的情况。

 

通常采用ZPL中的~DG指令(下载图形)【ZTOOLS工具生成GRF】和^XG指令(调用图形)或^IL指令(调用图形)【^XG与^IL的区别为:是否可以对图形进行缩放?】来完成这样一个过程。

 

~DG指令(下载图形)格式:

~DGd:o.GRF,t,w,data

d=存储图形的位置,可选的值:R,E,B,A

o=文件名,1-8个字母数字字符

t=图形占用字节数(bits)

w=每行的字节数

data=ASCII字符串

t参数的计算公式:

xz/8 * yz=t  (x=图形以mm为单位的宽度,y=图形以mm为单位的高度,z=dots/mm为单位的打印机分辨率,8=bits/byte)

比如,8mm宽,16mm高的图形,采用105sl-203dpi打印机打印,那么:

t=8*12/8*16*12=2304

 

^XG指令(调用图形)格式:

^XGd:o.GRF,mx,my

d=存储图形的源位置,可选的值:R,E,B,A

o=图形的文件名

mx=X轴的放大倍数,1-10

my=Y轴的放大倍数,1-10

 

^IL指令(调用图形)格式:

^ILd:o.GRF

d=存储图形的源位置,可选的值:R,E,B,A

o=图形的文件名

 

 

例子:

下载图形代码:

~DGR:SAMPLE.GRF,00080,010,
FFFFFFFFFFFFFFFFFFFF
8000FFFF0000FFFF0001
8000FFFF0000FFFF0001
8000FFFF0000FFFF0001
FFFF0000FFFF0000FFFF
FFFF0000FFFF0000FFFF
FFFF0000FFFF0000FFFF
FFFFFFFFFFFFFFFFFFFF

 

调用图形代码(^XG):

^XA
^F020,20^XGR:SAMPLE.GRF,1,1^FS  ^FO20,20^XGR:SAMPLE.GRF,1,1^FS
^XZ

 

调用图形代码(^IL):

^XA
^F020,20^ILR:SAMPLE.GRF^FS 应是 ^FO20,20^ILR:SAMPLE.GRF^FS
^XZ

 

如何把图片转换为GRF格式:

下面介绍如何把斑马logo转换为GRF格式

 

 

1、Logo图形的后缀名需要为PCX或者TIF

2、然后通过ZTOOLS工具中的Convert Graphic File功能,把PCX或者TIF的文件转换为GRF格式的文件。

斑马LOGO经过转换后的GRF格式的代码如下:

~DGR:ZLOGO,02180,020,E0000000000000000000000000000000000001A0
0000000000000000000000000000000000000040
8000000000000000000000000000000000000020
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000050000000000000000000000000
000000000000015C000000000000000000000000
0000000000080750000000000000000000000000
0000000000240440100000000000000000000000
0000000000181580200000000000000000000000
0000000000500D0020C000000000000000000000
0000000000200000200000000000000000000000
0000000081C01C00618000000000000000000000
0000000101807000400000000000000000000000
0000000502805800830000000000000000000000
00000002000078008C0000000000000000000000
00000004008020010A4000000000000000000000
0000000A03006800920000000000000000000000
0000060601805005440000000000000000000000
0000080001800406800000000000000000000000
00000C0C01401801180000000000000000000000
0000180801800A04600000000000000000000000
0000100600201681800000000000000000000000
0000100400900980000000000000000000000000
0014100200600380400000000000000000000000
002C200100181A00C00000000000000000000000
0010000680502502200000000000000000000000
01C8300100281C04C00000000000000000000000
0020100000100000400000000000000000000000
00F0280120A0B416900000000000000000000000
00181000C0009809680000000000000000000000
0068180040E08810200000000000000000000000
0050140181401860100000000000000000000000
0018090001419040080000000000000000000000
0004028282801080000000000000000000000000
0016020283820000002000000000000000000000
0008030102011C80002000000000000000000000
0002000500821830384000000000000000000000
00000106028008C4802000000000000000000000
0000820502810451506000000000000000000000
00000404028104A4D0D000000000000000000000
0000800600020348806000000000000000000000
00010E0601C50371E1D000000000000000000000
00000204000600A1021000000000000000000000
0000080101810711C20000000000000000000000
0006120501810041044040000000000000000000
00040C0400E200209800C0000000000000000000
000C060200C202C1282060000000000000000000
00041C0300230240C060A0000000000000000000
00081802802181C0204050000000000000000000
000C1200002A0101C10060000000000000000000
0000020140288080804180000000000000000000
00302C0080178001820100000000000000000000
00082C00400A4180018200000000000000000000
00001200300B8081020200000000000000000000
0058010010058080020221800000000000000000
00680600100240820C0402400000000000000000
000818002C004000041805A00000000000000000
007819000800F0021A385C800000000000000000
000816C002001080049066500000000000000000
00280B400D00200018C0B3200000000000000000
00880EA0068018820E2005600000000000000000
005004300140000211A1EAB00000000000000000
00580E280050000009801F480000000000000000
00300814016400000D011F800000000000000000
00100C000028000006041F680000000000000000
00400A02007A000000031F980000000000000000
002C0202800C0000000A1FA00000000000000000
004C01012011A00000051F500000000000000000
00140500A0125000001F1F400000000000000000
002401015808E00000081F800000000000000000
001806000205A0000005D3800000000000000000
0016018081C02000000250800000000000000000
00090200E020400000004C000000000000000000
0007038010304000000000000000000000000000
000D0180401C0000000000000000000000000000
0004000000138000000000000000000000000000
0002818018140000000000000000000000000000
00014060280A0000000000000000000000000000
000040E030020000000000000000000000000000
0001A0000004004CF20000010000000000000000
0000D040100000B19D0000036000000000000000
000020000800016D618000005000000000000000
000038280800000024000002A000000000000000
00000C3404000000180000023000000000000000
0000081800000000B2006401C1C0090402E00000
00001806020000022402AE8136B0162408200000
0000020C010000028005638336341CD0322F0000
000004818080000D700980C0E8040DA060150000
00000184000000142006812330251200000B0000
000002004000002200146A32D01A128002B40000
000000438000003400039B4140010B8029930000
000080A0400000CC0019A42250040A805A0C0000
020000129800004800160001A0011A0040050000
00400029700001B5B20280225829070074160000
04020019A0000100F008816308A80E80C4350000
0000000C400000FFFF8154C0D1AC10805A0A0000
0044200380000000E0017001B148048024870000
0040000200000000000000000000000000000000
0002000000000000000000000000000000000000
0002000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
8000000000000000000000000000000000000000
0000000000000000000000000000000000000000
8000000000000000000000000000000000000020
6000000000000000000000000000000000000080

 

 

实现:

帮助API 从网上下载 吧     ///<summary>

    /// ZPL帮助类

    ///</summary>

    publicclassZebraHelper;

核心代码

图片转为GRF 实现并输出

//不带位置

publicstring Convert(string s_FilePath)

        {

            int b = 0;

            long n = 0;

            long clr;

            StringBuilder sb = newStringBuilder();

            sb.Append("~DGR:ZLOGO.GRF,");

            Bitmap bm = newBitmap(s_FilePath);

            int w = ((bm.Size.Width / 8 + ((bm.Size.Width % 8 == 0) ? 0 : 1)) * bm.Size.Height);

            int h = (bm.Size.Width / 8 + ((bm.Size.Width % 8 == 0) ? 0 : 1));

 

            sb.Append(w.ToString().PadLeft(5, '0') + "," + h.ToString().PadLeft(3, '0') + ",\n");

            using (Bitmap bmp = newBitmap(bm.Size.Width, bm.Size.Height))

            {

                for (int y = 0; y < bm.Size.Height; y++)

                {

                    for (int x = 0; x < bm.Size.Width; x++)

                    {

                        b = b * 2;

                        clr = bm.GetPixel(x, y).ToArgb();

                        string s = clr.ToString("X");

 

                        if (s.Substring(s.Length - 6, 6).CompareTo("BBBBBB") < 0)

                        {

                            bmp.SetPixel(x, y, bm.GetPixel(x, y));

                            b++;

                        }

                        n++;

                        if (x == (bm.Size.Width - 1))

                        {

                            if (n < 8)

                            {

                                b = b * (2 ^ (8 - (int)n));

 

                                sb.Append(b.ToString("X").PadLeft(2, '0'));

                                b = 0;

                                n = 0;

                            }

                        }

                        if (n >= 8)

                        {

                            sb.Append(b.ToString("X").PadLeft(2, '0'));

                            b = 0;

                            n = 0;

                        }

                    }

                }

                sb.Append("^FO100,540^XGR:ZLOGO.GRF,2,2^FS");

            }

            return sb.ToString();

 

        }

 

//带位置

      publicstringConvert(string s_FilePath,intxtop,int ytop)

        {

            intb = 0;

            longn = 0;

            longclr;

            StringBuilder sb = newStringBuilder();

           sb.Append("~DGR:ZLOGO.GRF,");

            Bitmap bm = newBitmap(s_FilePath);

            intw = ((bm.Size.Width / 8 + ((bm.Size.Width % 8 == 0) ? 0 : 1)) *bm.Size.Height);

            inth = (bm.Size.Width / 8 + ((bm.Size.Width % 8 == 0) ? 0 : 1));

 

           sb.Append(w.ToString().PadLeft(5, '0')+ "," + h.ToString().PadLeft(3, '0') + ",\n");

            using(Bitmap bmp = newBitmap(bm.Size.Width, bm.Size.Height))

            {

               for (inty = 0; y < bm.Size.Height; y++)

               {

                   for (intx = 0; x < bm.Size.Width; x++)

                   {

                        b = b * 2;

                        clr = bm.GetPixel(x,y).ToArgb();

                        strings = clr.ToString("X");

 

                        if(s.Substring(s.Length - 6, 6).CompareTo("BBBBBB")< 0)

                        {

                            bmp.SetPixel(x, y,bm.GetPixel(x, y));

                            b++;

                        }

                        n++;

                        if(x == (bm.Size.Width - 1))

                        {

                           if(n < 8)

                            {

                                b = b * (2 ^ (8- (int)n));

 

                               sb.Append(b.ToString("X").PadLeft(2,'0'));

                                b = 0;

                                n = 0;

                            }

                        }

                        if(n >= 8)

                        {

                           sb.Append(b.ToString("X").PadLeft(2,'0'));

                            b = 0;

                            n = 0;

                        }

                   }

               }

               sb.Append(string.Format("^FO{0},{1}^XGR:ZLOGO.GRF,2,2^FS", xtop,ytop));

            }

            returnsb.ToString();

 

        }



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