Search in sources :

Example 56 with NotFoundException

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;
}
Also used : QRCodeReader(com.google.zxing.qrcode.QRCodeReader) DecodeHintType(com.google.zxing.DecodeHintType) Hashtable(java.util.Hashtable) PlanarYUVLuminanceSource(com.google.zxing.PlanarYUVLuminanceSource) NotFoundException(com.google.zxing.NotFoundException) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) NotFoundException(com.google.zxing.NotFoundException) ReaderException(com.google.zxing.ReaderException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Result(com.google.zxing.Result)

Example 57 with NotFoundException

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;
}
Also used : PlanarYUVLuminanceSource(com.google.zxing.PlanarYUVLuminanceSource) ChecksumException(com.google.zxing.ChecksumException) NotFoundException(com.google.zxing.NotFoundException) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) FormatException(com.google.zxing.FormatException) Result(com.google.zxing.Result) Nullable(androidx.annotation.Nullable)

Aggregations

NotFoundException (com.google.zxing.NotFoundException)57 ResultPoint (com.google.zxing.ResultPoint)38 BinaryBitmap (com.google.zxing.BinaryBitmap)21 Result (com.google.zxing.Result)21 FormatException (com.google.zxing.FormatException)13 HybridBinarizer (com.google.zxing.common.HybridBinarizer)13 DecodeHintType (com.google.zxing.DecodeHintType)12 ChecksumException (com.google.zxing.ChecksumException)9 FinderPattern (com.google.zxing.oned.rss.FinderPattern)9 ResultPointCallback (com.google.zxing.ResultPointCallback)8 BitArray (com.google.zxing.common.BitArray)7 BitMatrix (com.google.zxing.common.BitMatrix)7 ReaderException (com.google.zxing.ReaderException)6 DecoderResult (com.google.zxing.common.DecoderResult)6 Hashtable (java.util.Hashtable)6 MultiFormatReader (com.google.zxing.MultiFormatReader)5 Decoder (com.google.zxing.aztec.decoder.Decoder)5 DetectorResult (com.google.zxing.common.DetectorResult)5 QRCodeReader (com.google.zxing.qrcode.QRCodeReader)5 EnumMap (java.util.EnumMap)5