好的,所以我要抓住这里有人曾经使用过zxing的机会.我正在开发一个Java应用程序,它需要做的一件事就是将一个字节数据数组编码为QR代码,然后再对其进行解码.
这是我的编码器的示例:
byte[] b = {0x48, 0x45, 0x4C, 0x4C, 0x4F};
//convert the byte array into a UTF-8 string
String data;
try {
data = new String(b, "UTF8");
}
catch (UnsupportedEncodingException e) {
//the program shouldn't be able to get here
return;
}
//get a byte matrix for the data
ByteMatrix matrix;
com.google.zxing.Writer writer = new QRCodeWriter();
try {
matrix = writer.encode(data, com.google.zxing.BarcodeFormat.QR_CODE, width, height);
}
catch (com.google.zxing.WriterException e) {
//exit the method
return;
}
//generate an image from the byte …Run Code Online (Sandbox Code Playgroud)