Search in sources :

Example 41 with NotFoundException

use of com.google.zxing.NotFoundException in project android-zxing by PearceXu.

the class RSS14Reader method decodePair.

private Pair decodePair(BitArray row, boolean right, int rowNumber, Map<DecodeHintType, ?> hints) {
    try {
        int[] startEnd = findFinderPattern(row, right);
        FinderPattern pattern = parseFoundFinderPattern(row, rowNumber, right, startEnd);
        ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
        if (resultPointCallback != null) {
            float center = (startEnd[0] + startEnd[1]) / 2.0f;
            if (right) {
                // row is actually reversed
                center = row.getSize() - 1 - center;
            }
            resultPointCallback.foundPossibleResultPoint(new ResultPoint(center, rowNumber));
        }
        DataCharacter outside = decodeDataCharacter(row, pattern, true);
        DataCharacter inside = decodeDataCharacter(row, pattern, false);
        return new Pair(1597 * outside.getValue() + inside.getValue(), outside.getChecksumPortion() + 4 * inside.getChecksumPortion(), pattern);
    } catch (NotFoundException ignored) {
        return null;
    }
}
Also used : ResultPointCallback(com.google.zxing.ResultPointCallback) ResultPoint(com.google.zxing.ResultPoint) NotFoundException(com.google.zxing.NotFoundException)

Example 42 with NotFoundException

use of com.google.zxing.NotFoundException in project android-zxing by PearceXu.

the class RSSExpandedReader method checkRows.

// Try to construct a valid rows sequence
// Recursion is used to implement backtracking
private List<ExpandedPair> checkRows(List<ExpandedRow> collectedRows, int currentRow) throws NotFoundException {
    for (int i = currentRow; i < rows.size(); i++) {
        ExpandedRow row = rows.get(i);
        this.pairs.clear();
        for (ExpandedRow collectedRow : collectedRows) {
            this.pairs.addAll(collectedRow.getPairs());
        }
        this.pairs.addAll(row.getPairs());
        if (!isValidSequence(this.pairs)) {
            continue;
        }
        if (checkChecksum()) {
            return this.pairs;
        }
        List<ExpandedRow> rs = new ArrayList<>();
        rs.addAll(collectedRows);
        rs.add(row);
        try {
            // Recursion: try to add more rows
            return checkRows(rs, i + 1);
        } catch (NotFoundException e) {
        // We failed, try the next candidate
        }
    }
    throw NotFoundException.getNotFoundInstance();
}
Also used : ArrayList(java.util.ArrayList) NotFoundException(com.google.zxing.NotFoundException) ResultPoint(com.google.zxing.ResultPoint)

Example 43 with NotFoundException

use of com.google.zxing.NotFoundException in project barcodescanner by dm77.

the class ZXingScannerView method onPreviewFrame.

@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    if (mResultHandler == null) {
        return;
    }
    try {
        Camera.Parameters parameters = camera.getParameters();
        Camera.Size size = parameters.getPreviewSize();
        int width = size.width;
        int height = size.height;
        if (DisplayUtils.getScreenOrientation(getContext()) == Configuration.ORIENTATION_PORTRAIT) {
            int rotationCount = getRotationCount();
            if (rotationCount == 1 || rotationCount == 3) {
                int tmp = width;
                width = height;
                height = tmp;
            }
            data = getRotatedData(data, camera);
        }
        Result rawResult = null;
        PlanarYUVLuminanceSource source = buildLuminanceSource(data, width, height);
        if (source != null) {
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            try {
                rawResult = mMultiFormatReader.decodeWithState(bitmap);
            } catch (ReaderException re) {
            // continue
            } catch (NullPointerException npe) {
            // This is terrible
            } catch (ArrayIndexOutOfBoundsException aoe) {
            } finally {
                mMultiFormatReader.reset();
            }
            if (rawResult == null) {
                LuminanceSource invertedSource = source.invert();
                bitmap = new BinaryBitmap(new HybridBinarizer(invertedSource));
                try {
                    rawResult = mMultiFormatReader.decodeWithState(bitmap);
                } catch (NotFoundException e) {
                // continue
                } finally {
                    mMultiFormatReader.reset();
                }
            }
        }
        final Result finalRawResult = rawResult;
        if (finalRawResult != null) {
            Handler handler = new Handler(Looper.getMainLooper());
            handler.post(new Runnable() {

                @Override
                public void run() {
                    // Stopping the preview can take a little long.
                    // So we want to set result handler to null to discard subsequent calls to
                    // onPreviewFrame.
                    ResultHandler tmpResultHandler = mResultHandler;
                    mResultHandler = null;
                    stopCameraPreview();
                    if (tmpResultHandler != null) {
                        tmpResultHandler.handleResult(finalRawResult);
                    }
                }
            });
        } else {
            camera.setOneShotPreviewCallback(this);
        }
    } catch (RuntimeException e) {
        // TODO: Terrible hack. It is possible that this method is invoked after camera is released.
        Log.e(TAG, e.toString(), e);
    }
}
Also used : NotFoundException(com.google.zxing.NotFoundException) Handler(android.os.Handler) HybridBinarizer(com.google.zxing.common.HybridBinarizer) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException) PlanarYUVLuminanceSource(com.google.zxing.PlanarYUVLuminanceSource) LuminanceSource(com.google.zxing.LuminanceSource) PlanarYUVLuminanceSource(com.google.zxing.PlanarYUVLuminanceSource) Camera(android.hardware.Camera) BinaryBitmap(com.google.zxing.BinaryBitmap)

Example 44 with NotFoundException

use of com.google.zxing.NotFoundException in project SmartMesh_Android by SmartMeshFoundation.

the class CaptureActivity method scanningImage.

/**
 * Scan the qr code image method
 */
public Result scanningImage(String path) {
    if (TextUtils.isEmpty(path)) {
        return null;
    }
    Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
    // Set the qr code coding content
    hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
    BitmapFactory.Options options = new BitmapFactory.Options();
    // To obtain the original size
    options.inJustDecodeBounds = true;
    scanBitmap = BitmapFactory.decodeFile(path, options);
    // To get the new size
    options.inJustDecodeBounds = false;
    int sampleSize = (int) (options.outHeight / (float) 200);
    if (sampleSize <= 0)
        sampleSize = 1;
    options.inSampleSize = sampleSize;
    scanBitmap = BitmapFactory.decodeFile(path, options);
    RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
    BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        return reader.decode(bitmap1, hints);
    } catch (NotFoundException e) {
        e.printStackTrace();
    } catch (ChecksumException e) {
        e.printStackTrace();
    } catch (FormatException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : QRCodeReader(com.google.zxing.qrcode.QRCodeReader) DecodeHintType(com.google.zxing.DecodeHintType) Hashtable(java.util.Hashtable) ChecksumException(com.google.zxing.ChecksumException) NotFoundException(com.google.zxing.NotFoundException) HybridBinarizer(com.google.zxing.common.HybridBinarizer) FormatException(com.google.zxing.FormatException) BitmapFactory(android.graphics.BitmapFactory) BinaryBitmap(com.google.zxing.BinaryBitmap)

Example 45 with NotFoundException

use of com.google.zxing.NotFoundException in project summer-android by cn-cerc.

the class FrmScanBarcode method scanningImage.

/**
 * 识别二维码图片中的数据
 *
 * @param path
 * @return
 */
public Result scanningImage(String path) {
    if (TextUtils.isEmpty(path)) {
        return null;
    }
    Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
    // 设置二维码内容的编码
    hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
    BitmapFactory.Options options = new BitmapFactory.Options();
    // 先获取原大小
    options.inJustDecodeBounds = true;
    scanBitmap = BitmapFactory.decodeFile(path, options);
    // 获取新的大小
    options.inJustDecodeBounds = false;
    int sampleSize = (int) (options.outHeight / (float) 200);
    if (sampleSize <= 0)
        sampleSize = 1;
    options.inSampleSize = sampleSize;
    scanBitmap = BitmapFactory.decodeFile(path, options);
    RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
    BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    try {
        return reader.decode(bitmap1, hints);
    } catch (NotFoundException e) {
        e.printStackTrace();
    } catch (ChecksumException e) {
        e.printStackTrace();
    } catch (FormatException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : QRCodeReader(com.google.zxing.qrcode.QRCodeReader) DecodeHintType(com.google.zxing.DecodeHintType) Hashtable(java.util.Hashtable) ChecksumException(com.google.zxing.ChecksumException) NotFoundException(com.google.zxing.NotFoundException) HybridBinarizer(com.google.zxing.common.HybridBinarizer) FormatException(com.google.zxing.FormatException) BitmapFactory(android.graphics.BitmapFactory) BinaryBitmap(com.google.zxing.BinaryBitmap) RGBLuminanceSource(cn.cerc.summer.android.parts.barcode.zxing.decoding.RGBLuminanceSource)

Aggregations

NotFoundException (com.google.zxing.NotFoundException)56 ResultPoint (com.google.zxing.ResultPoint)38 Result (com.google.zxing.Result)22 BinaryBitmap (com.google.zxing.BinaryBitmap)20 DecodeHintType (com.google.zxing.DecodeHintType)12 FormatException (com.google.zxing.FormatException)12 HybridBinarizer (com.google.zxing.common.HybridBinarizer)12 FinderPattern (com.google.zxing.oned.rss.FinderPattern)9 ChecksumException (com.google.zxing.ChecksumException)8 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 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 BitmapFactory (android.graphics.BitmapFactory)4