我有一个来自移动打印机制造商的二维码样本(下图)。我需要知道的是如何生成相同格式的新二维码?如何以这种格式创建二维码(实际上我更喜欢字节数组)。
让我感到困惑的是十六进制数据,它不是方形的,也不是像我期望的 QR 码那样代表“开”和“关”。我尝试过使用 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 03 33 33 0F 0 0 0 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 0 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 3030 F0 F0 F0 F0 F0 F0 30 30 F0 F0 00 00 00 00 30 30 00 00 0D
图片:
编辑
这是文档:
3.24 ESC K Nl Nh d1 d2….dK
[名称] 选择位图打印模式 1
[格式] ASCII ESC K nL nH d1….dK
Hex 1B 4B nL nH d1….dK
Decimal 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;