QR码字节数据

时间:2013-08-04 15:37:49

标签: android qr-code

我有来自制造商的移动打印机的QR码样本(如下)。我需要知道的是如何以相同的格式生成新的QR码?如何以这种格式创建QR码(实际上我更喜欢字节数组)。

让我感到困惑的是十六进制数据,它不是正方形,也不像我想要的QR代码那样代表“ons”和“offs”。我尝试过使用Zxing:

public byte[] CreateQRCode()
{
    Charset charset = Charset.forName("UTF-8");
    CharsetEncoder encoder = charset.newEncoder();
    byte[] b = null;
    try {
        // Convert a string to UTF-8 bytes in a ByteBuffer
        ByteBuffer bbuf = encoder.encode(CharBuffer.wrap("utf 8 characters - i used hebrew, but you should write some of your own language characters"));
        b = bbuf.array();
    } catch (CharacterCodingException e) {
        System.out.println(e.getMessage());
    }

    String data;
    try {
        data = new String(b, "UTF-8");
        // get a byte matrix for the data
        BitMatrix matrix = null;
        int h = 100;
        int w = 100;
        com.google.zxing.Writer writer = new MultiFormatWriter();
        try {
            Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(2);
            hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
            matrix = writer.encode(data,
                    com.google.zxing.BarcodeFormat.QR_CODE, w, h, hints);
        } catch (com.google.zxing.WriterException e) {
            System.out.println(e.getMessage());
        }
        //matrix.get(x, y) returns a boolean
        //matrix.getRow(arg0, arg1) takes a BitRow as a parameter - not sure how to use that method         
    } catch (UnsupportedEncodingException e) {
        System.out.println(e.getMessage());
    }       
}

zxing代码令人困惑的是它将宽度和高度作为参数...他们是否只为此图书馆编写图像来生成图像?

十六进制二维码:
1B 4B 2E 00 00 00 3F 3F 30 30 33 33 33 33 33 33 30 30 3F 3F 00 00 00 00 0C 0C 0F 0F 30 30 03 03 00 00 3F 3F 30 30 33 33 33 33 33 33 30 30 3F 3F 00 00 0D 1B 4B 2E 00 00 00 FF FF 03 03 F3 F3 F3 F3 F3 F3 03 03 FF FF 00 00 CF CF FC FC 3F 3F 0C 0C CF CF 00 00 FF FF 03 03 F3 F3 F3 F3 F3 F3 03 03 FF FF 00 00 0D 1B 4B 2E 00 00 00 0F 0F 3C 3C 3C 3C 0C 0C 00 00 0F 0F 33 33 00 00 CC CC FC FC CF CF 3C 3C 00 00 0F 0F 3C 3C 3F 3F 03 03 33 33 00 00 0C 0C 0F 0F 00 00 0D 1B 4B 2E 00 00 00 C3 C3 F3 F3 33 33 33 33 C3 C3 03 03 33 33 F0 F0 0C 0C FC FC 03 03 CC CC FF FF F0 F0 F3 F3 F0 F0 30 30 FC FC 0C 0C 3C 3C 3F 3F 00 00 0D 1B 4B 2E 00 00 00 FF FF 00 00 3F 3F 3F 3F 3F 3F 00 00 FF FF 00 00 03 03 F0 F0 3C 3C FF FF F3 F3 0F 0F 3C 3C 03 03 C3 C3 CF CF 00 00 C3 C3 33 33 00 00 0D 1B 4B 2E 00 00 00 F0 F0 30 30 30 30 30 30 30 30 30 30 F0 F0 00 00 C0 C0 C0 C0 C0 C0 F0 F0 30 30 F0 F0 F0 F0 F0 F0 30 30 F0 F0 00 00 00 00 30 30 00 00 0D


图片:
enter image description here

修改

这是文件:
3.24 ESC K Nl Nh d1 d2 ... .dK
[名称]选择位图打印模式1
[格式] ASCII ESC K nL nH d1 ... .dK
Hex 1B 4B nL nH d1 ... .dK
小数27 75 nL nH d1 ... .dK
[范围]
0≤nL≤255
0≤nH≤1
0≤d≤255
[描述]该命令的最大高度为8个点,最大宽度为可打印区域;
nL nH是无字符位图的低位和高位,它表示位图中的点 [注意]
•此命令受放大字符命令的控制;
当打印机调整反向打印命令时,此位图将从下到上打印。

[Program example ]
Unsigned char Str[30];
Unsigned char i=0;
Str[i++] = 0x1B;
Str[i++] = 0x4B;
Str[i++] = 15; print 15-dot wide bitmap;
Str[i++] = 0x7C; Str[i++] = 0x44; Str[i++] = 0x44; Str[i++] = 0xFF;
Str[i++] = 0x44; Str[i++] = 0x44; Str[i++] = 0x7C; Str[i++] = 0x00;
Str[i++] = 0x41; Str[i++] = 0x62; Str[i++] = 0x54; Str[i++] = 0XC8;
Str[i++] = 0x54; Str[i++] = 0x62; Str[i++] = 0x41; Str[i++] = 0x0D;
SendDataToPrinter(Str,i); send bitmap command;

1 个答案:

答案 0 :(得分:0)

你是什么意思'同样的格式' - 只是,QR码?那么是的,你做得对。

该方法采用宽度/高度,因为对于某些其他格式,没有它就没有意义。如果您只想要每个“像素”有1个模块的原始QR码,请查看Encode类本身。

您的测试二维码说“prova”。我不确定十六进制应该在这里。 目前还不清楚最终部分是什么。如果它描述了所需的格式,那么它不是你的例子。

这需要很多澄清。