Android 二维码字节数据

Android 二维码字节数据,android,qr-code,Android,Qr Code,我有一个移动打印机制造商的二维码样本(见下图)。我需要知道的是如何生成相同格式的新二维码?如何创建这种格式的二维码(实际上我更喜欢字节数组) 让我困惑的是十六进制数据,它不是正方形,也不像我期望的二维码那样代表“开”和“关”。我试过使用Zxing: public byte[] CreateQRCode() { Charset charset = Charset.forName("UTF-8"); CharsetEncoder encoder = charset.newEncode

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

让我困惑的是十六进制数据,它不是正方形,也不像我期望的二维码那样代表“开”和“关”。我试过使用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());
    }       
}

“相同格式”是什么意思?只是二维码?那是的,你做得对

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

您的测试二维码显示“prova”。我不知道这里应该有什么妖术。 也不清楚结尾部分是什么。如果它描述了所需的格式,那么它不是您的示例所遵循的格式

这需要很多澄清

[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;