use of com.google.zxing.NotFoundException in project QrCodeScanner by ekibun.
the class Decoder method decode.
public static Result decode(byte[] data, int width, int height, Rect crop) {
Result result = null;
try {
Hashtable<DecodeHintType, Object> hints = new Hashtable<>();
hints.put(DecodeHintType.CHARACTER_SET, "ISO-8859-1");
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
/*
Collection<BarcodeFormat> barcodeFormats = new ArrayList<>();
barcodeFormats.add(BarcodeFormat.QR_CODE);
barcodeFormats.add(BarcodeFormat.CODE_39);
barcodeFormats.add(BarcodeFormat.CODE_93);
barcodeFormats.add(BarcodeFormat.CODE_128);
hints.put(DecodeHintType.POSSIBLE_FORMATS, barcodeFormats);*/
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, crop.left, crop.top, crop.width(), crop.height(), false);
// BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
result = new QRCodeReader().decode(bitmap1, hints);
} catch (NotFoundException e) {
// e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of com.google.zxing.NotFoundException in project Signal-Android by signalapp.
the class ScanningThread method getScannedData.
@Nullable
private String getScannedData(byte[] data, int width, int height, int orientation) {
try {
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
rotatedData[x * height + height - y - 1] = data[x + y * width];
}
}
int tmp = width;
width = height;
height = tmp;
data = rotatedData;
}
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = reader.decode(bitmap, hints);
if (result != null)
return result.getText();
} catch (NullPointerException | ChecksumException | FormatException e) {
Log.w(TAG, e);
} catch (NotFoundException e) {
// Thanks ZXing...
}
return null;
}
Aggregations