use of jp.sourceforge.qrcode.exception.DecodingFailedException in project qrcode by yanbe.
the class QRCodeDecoder method decode.
public byte[] decode(QRCodeImage qrCodeImage) throws DecodingFailedException {
Point[] adjusts = getAdjustPoints();
Vector results = new Vector();
numTryDecode = 0;
while (numTryDecode < adjusts.length) {
try {
DecodeResult result = decode(qrCodeImage, adjusts[numTryDecode]);
if (result.isCorrectionSucceeded()) {
return result.getDecodedBytes();
} else {
results.addElement(result);
canvas.println("Decoding succeeded but could not correct");
canvas.println("all errors. Retrying..");
}
} catch (DecodingFailedException dfe) {
if (dfe.getMessage().indexOf("Finder Pattern") >= 0)
throw dfe;
} finally {
numTryDecode += 1;
}
}
if (results.size() == 0)
throw new DecodingFailedException("Give up decoding");
int minErrorIndex = -1;
int minError = Integer.MAX_VALUE;
for (int i = 0; i < results.size(); i++) {
DecodeResult result = (DecodeResult) results.elementAt(i);
if (result.getNumCorrectuionFailures() < minError) {
minError = result.getNumCorrectuionFailures();
minErrorIndex = i;
}
}
canvas.println("All trials need for correct error");
canvas.println("Reporting #" + (minErrorIndex) + " that,");
canvas.println("corrected minimum errors (" + minError + ")");
canvas.println("Decoding finished.");
return ((DecodeResult) results.elementAt(minErrorIndex)).getDecodedBytes();
}
Aggregations