java - Google Zxing library NotFoundException on valid QR code -
i'm using zxing java library encode , decode qr code in application goal store on printed paper critical information, small database (less 200 kb) spliting data in 2kb blocks , generating as qrcode required. i'm using latest zxing library available downloaded maven repository : zxing-core-3.3.0
.
i found random failure build little program generate randomly byte array, convert base64 ascii chars , try encode/decome them. isolated data combination fails :
public class qr4jerrormain { private static bufferedimage buffer; public static void main(string[] args) { try { string encodetext = "tsighjcuhuxlu7l8czj31+mpc9c50h/cat7co5/wvicofzkso63q5orutsrfi+4/" + "0chmlki4iggksiphoy7rqyzbugor58pbshb4lzlxo6nneg64bdg5rstidnczcrhldy9ir2whar" + "pihqvfeimebcmrf0xmcaoptremcxknxmhaxwlqw4sq1/etojfizdpe7/uoimhjusxdhfpeokr+" + "0batc7pxfym4tsmjne036gzsdl4tijf57w8wgkllozlfm3tyr06ousig345zms6+g9rlbtwkcn" + "arjaon42hsybzyrx0y1pfm94d0xs4wdb24cyfex/9cu3avlzcc3tx8zqqnqzbsb6xrtjshdxud" + "onodkxlprxvpcoaa6v9qzf92irdaqje/elx6kyrnt8tcfoekgn4tske7twpbybanx6jg6dxcpc" + "m9d4+p+kgjc/28trc1hwu33dqlqko24csjcyliymj4vn4bhld4qmkhci0wbieuqwkqwinptdnl" + "ajngxybbrh4kre2nicumfwn5zpnnczr3ocq4zd8zwgukdymdebxqdcwxgx4yboky6hqnzte4lh" + "n2zsrkuh"; // create qr boolean encodestatus = createqr2(encodetext); if(!encodestatus) { system.err.println("error while creating qr"); } // read qr string result = readqr2(); // compare data boolean equals = arrays.equals(encodetext.getbytes(), result.getbytes()); } catch(exception exc) { exc.printstacktrace(); } } private static final boolean createqr2(string text/*, string filename*/) { try { // bitmatrix bitmatrix bm = new qrcodewriter().encode(text, barcodeformat.qr_code, 50, 50); // encode text qr code export image buffer = new bufferedimage(bm.getwidth(), bm.getheight(), bufferedimage.type_int_rgb); // fill pixels qr data for(int ii = 0; ii < bm.getwidth(); ii++) { for(int jj = 0; jj < bm.getheight(); jj++) { buffer.setrgb(ii, jj, bm.get(ii, jj) ? color.black.getrgb() : color.white.getrgb()); } } // optional write image bitmap file return imageio.write(buffer, "bmp", new file("failureqr.bmp")); } catch(exception exc) { exc.printstacktrace(); return false; } } private static final string readqr2() throws exception { luminancesource ls = new bufferedimageluminancesource(buffer); binarybitmap binbitmap = new binarybitmap(new hybridbinarizer(ls)); system.out.println("are binarybitmap equals ? " + bitmatrix.equals(binbitmap.getblackmatrix())); result result = new qrcodereader().decode(binbitmap); return result.gettext(); } }
if run code, produce following 93*93 qr code:
this piece of code throws com.google.zxing.formatexception
exception without details.
as can see in code, not use bitmap file decode qr (to remove uncertainty picture write/read method). use directly same bufferedimage
object in memory created previously. (using bitmap file leads same result)
the qr code valid, can decoded smartphone app, , give same text input.
so, why there trouble input data? should (or not do) have reliable decoding solution?
edit: same dataset encoded/decoded aztec or pdf_417 barcode format works.
edit2: updated method readqr2()
, both bitmatrix
objects equals. issue not coming image parser, comes qrcodereader.decode()
itself.
Comments
Post a Comment