我有一個移動打印機制造商(下)的QR碼示例。我需要知道的是如何以相同的格式生成新的QR碼?如何以這種格式創建QR碼(實際上我更喜歡一個字節數組)。QR代碼字節數據
令我困惑的是十六進制數據,它不是方形的,也不像我期望的QR碼那樣代表「ons」和「offs」。
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());
}
}
什麼是混淆有關斑馬線的代碼是,它需要的寬度和高度爲參數......他們才只寫這個庫爲它產生的圖像:我一直在使用斑馬線試過嗎?
十六進制QR碼:
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
圖片:
EDIT
這是文檔:
3.24 ESCķNL新罕布什爾D1 D2 ...沒有自動跳轉
[名稱]選擇位圖打印模式1
[格式] ASCII ESCķ納升nH的D1 ...沒有自動跳轉
十六進制碼1B 4B納升nH的D1 ...沒有自動跳轉
十進制27 75納升nH的D1 ...沒有自動跳轉
[範圍]
0≤納升≤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;