com.google.zxing.ReaderException Java Examples
The following examples show how to use
com.google.zxing.ReaderException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MultiDetector.java From ZXing-Orient with Apache License 2.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #2
Source File: ScanActivity.java From Conversations with GNU General Public License v3.0 | 6 votes |
private void decode(final byte[] data) { final PlanarYUVLuminanceSource source = cameraManager.buildLuminanceSource(data); final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, (ResultPointCallback) dot -> runOnUiThread(() -> scannerView.addDot(dot))); final Result scanResult = reader.decode(bitmap, hints); runOnUiThread(() -> handleResult(scanResult)); } catch (final ReaderException x) { // retry cameraHandler.post(fetchAndDecodeRunnable); } finally { reader.reset(); } }
Example #3
Source File: MultiDetector.java From Tesseract-OCR-Scanner with Apache License 2.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #4
Source File: DecodeUtils.java From SimplifyReader with Apache License 2.0 | 6 votes |
public String decodeWithZxing(byte[] data, int width, int height, Rect crop) { MultiFormatReader multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(changeZXingDecodeDataMode()); Result rawResult = null; PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, crop.left, crop.top, crop.width(), crop.height(), false); if (source != null) { BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { rawResult = multiFormatReader.decodeWithState(bitmap); } catch (ReaderException re) { // continue } finally { multiFormatReader.reset(); } } return rawResult != null ? rawResult.getText() : null; }
Example #5
Source File: DecodeUtils.java From SimplifyReader with Apache License 2.0 | 6 votes |
public String decodeWithZxing(Bitmap bitmap) { MultiFormatReader multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(changeZXingDecodeDataMode()); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); Result rawResult = null; RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); if (source != null) { BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); try { rawResult = multiFormatReader.decodeWithState(binaryBitmap); } catch (ReaderException re) { // continue } finally { multiFormatReader.reset(); } } return rawResult != null ? rawResult.getText() : null; }
Example #6
Source File: MultiDetector.java From weex with Apache License 2.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #7
Source File: MultiDetector.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #8
Source File: DecodeTask.java From code-scanner with MIT License | 6 votes |
@Nullable @SuppressWarnings("SuspiciousNameCombination") public Result decode(@NonNull final MultiFormatReader reader) throws ReaderException { int imageWidth = mImageSize.getX(); int imageHeight = mImageSize.getY(); final int orientation = mOrientation; final byte[] image = Utils.rotateYuv(mImage, imageWidth, imageHeight, orientation); if (orientation == 90 || orientation == 270) { final int width = imageWidth; imageWidth = imageHeight; imageHeight = width; } final Rect frameRect = Utils.getImageFrameRect(imageWidth, imageHeight, mViewFrameRect, mPreviewSize, mViewSize); final int frameWidth = frameRect.getWidth(); final int frameHeight = frameRect.getHeight(); if (frameWidth < 1 || frameHeight < 1) { return null; } return Utils.decodeLuminanceSource(reader, new PlanarYUVLuminanceSource(image, imageWidth, imageHeight, frameRect.getLeft(), frameRect.getTop(), frameWidth, frameHeight, mReverseHorizontal)); }
Example #9
Source File: MultiDetector.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(EMPTY_DETECTOR_RESULTS); } }
Example #10
Source File: BarcodeUtils.java From code-scanner with MIT License | 6 votes |
/** * Decode barcode from YUV pixels array * * @param pixels YUV image data * @param width Image width * @param height Image height * @param rotation Degrees to rotate image before decoding (only 0, 90, 180 or 270 are allowed) * @param reverseHorizontal Reverse image horizontally before decoding * @param hints Decoder hints * @return Decode result, if barcode was decoded successfully, {@code null} otherwise * @see DecodeHintType */ @Nullable @SuppressWarnings("SuspiciousNameCombination") public static Result decodeYuv(@NonNull final byte[] pixels, final int width, final int height, @Rotation final int rotation, final boolean reverseHorizontal, @Nullable final Map<DecodeHintType, ?> hints) { Objects.requireNonNull(pixels); final byte[] rotatedPixels = Utils.rotateYuv(pixels, width, height, rotation); final int rotatedWidth; final int rotatedHeight; if (rotation == ROTATION_90 || rotation == ROTATION_270) { rotatedWidth = height; rotatedHeight = width; } else { rotatedWidth = width; rotatedHeight = height; } final MultiFormatReader reader = createReader(hints); try { return Utils.decodeLuminanceSource(reader, new PlanarYUVLuminanceSource(rotatedPixels, rotatedWidth, rotatedHeight, 0, 0, rotatedWidth, rotatedHeight, reverseHorizontal)); } catch (final ReaderException e) { return null; } }
Example #11
Source File: QrCodeCreateUtil.java From java-study with Apache License 2.0 | 6 votes |
/** * 读二维码并输出携带的信息 */ public static void readQrCode(InputStream inputStream) throws IOException { //从输入流中获取字符串信息 BufferedImage image = ImageIO.read(inputStream); //将图像转换为二进制位图源 LuminanceSource source = new BufferedImageLuminanceSource(image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); Result result = null; try { result = reader.decode(bitmap); } catch (ReaderException e) { e.printStackTrace(); } System.out.println(result.getText()); }
Example #12
Source File: MultiDetector.java From reacteu-app with MIT License | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<DetectorResult>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #13
Source File: DecodeUtils.java From myapplication with Apache License 2.0 | 6 votes |
public Result decodeWithZxing(Bitmap bitmap) { MultiFormatReader multiFormatReader = new MultiFormatReader(); multiFormatReader.setHints(changeZXingDecodeDataMode()); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); Result rawResult = null; RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels); BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source)); try { rawResult = multiFormatReader.decodeWithState(binaryBitmap); } catch (ReaderException re) { // continue } finally { multiFormatReader.reset(); } return rawResult; }
Example #14
Source File: ScanActivity.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
private void decode(final byte[] data) { final PlanarYUVLuminanceSource source = cameraManager.buildLuminanceSource(data); final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); try { hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, (ResultPointCallback) dot -> runOnUiThread(() -> scannerView.addDot(dot))); final Result scanResult = reader.decode(bitmap, hints); runOnUiThread(() -> handleResult(scanResult)); } catch (final ReaderException x) { // retry cameraHandler.post(fetchAndDecodeRunnable); } finally { reader.reset(); } }
Example #15
Source File: MultiDetector.java From ScreenCapture with MIT License | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #16
Source File: MultiDetector.java From QrCodeScanner with GNU General Public License v3.0 | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #17
Source File: MultiDetector.java From barcodescanner-lib-aar with MIT License | 6 votes |
public DetectorResult[] detectMulti(Map<DecodeHintType,?> hints) throws NotFoundException { BitMatrix image = getImage(); ResultPointCallback resultPointCallback = hints == null ? null : (ResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); MultiFinderPatternFinder finder = new MultiFinderPatternFinder(image, resultPointCallback); FinderPatternInfo[] infos = finder.findMulti(hints); if (infos.length == 0) { throw NotFoundException.getNotFoundInstance(); } List<DetectorResult> result = new ArrayList<>(); for (FinderPatternInfo info : infos) { try { result.add(processFinderPatternInfo(info)); } catch (ReaderException e) { // ignore } } if (result.isEmpty()) { return EMPTY_DETECTOR_RESULTS; } else { return result.toArray(new DetectorResult[result.size()]); } }
Example #18
Source File: UPCEANExtensionSupport.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
Result decodeRow(int rowNumber, BitArray row, int rowOffset) throws NotFoundException { int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN); try { return fiveSupport.decodeRow(rowNumber, row, extensionStartRange); } catch (ReaderException ignored) { return twoSupport.decodeRow(rowNumber, row, extensionStartRange); } }
Example #19
Source File: QRCodeMultiReader.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
@Override public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException { List<Result> results = new ArrayList<>(); DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); for (DetectorResult detectorResult : detectorResults) { try { DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints); ResultPoint[] points = detectorResult.getPoints(); // If the code was mirrored: swap the bottom-left and the top-right points. if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) { ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); List<byte[]> byteSegments = decoderResult.getByteSegments(); if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } String ecLevel = decoderResult.getECLevel(); if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } if (decoderResult.hasStructuredAppend()) { result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.getStructuredAppendSequenceNumber()); result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.getStructuredAppendParity()); } results.add(result); } catch (ReaderException re) { // ignore and continue } } if (results.isEmpty()) { return EMPTY_RESULT_ARRAY; } else { results = processStructuredAppend(results); return results.toArray(new Result[results.size()]); } }
Example #20
Source File: MultiFormatOneDReader.java From weex with Apache License 2.0 | 5 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { for (OneDReader reader : readers) { try { return reader.decodeRow(rowNumber, row, hints); } catch (ReaderException re) { // continue } } throw NotFoundException.getNotFoundInstance(); }
Example #21
Source File: MultiFormatOneDReader.java From analyzer-of-android-for-Apache-Weex with Apache License 2.0 | 5 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { for (OneDReader reader : readers) { try { return reader.decodeRow(rowNumber, row, hints); } catch (ReaderException re) { // continue } } throw NotFoundException.getNotFoundInstance(); }
Example #22
Source File: QRCodeMultiReader.java From ZXing-Orient with Apache License 2.0 | 5 votes |
@Override public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException { List<Result> results = new ArrayList<>(); DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); for (DetectorResult detectorResult : detectorResults) { try { DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints); ResultPoint[] points = detectorResult.getPoints(); // If the code was mirrored: swap the bottom-left and the top-right points. if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) { ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); List<byte[]> byteSegments = decoderResult.getByteSegments(); if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } String ecLevel = decoderResult.getECLevel(); if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } if (decoderResult.hasStructuredAppend()) { result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.getStructuredAppendSequenceNumber()); result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.getStructuredAppendParity()); } results.add(result); } catch (ReaderException re) { // ignore and continue } } if (results.isEmpty()) { return EMPTY_RESULT_ARRAY; } else { results = processStructuredAppend(results); return results.toArray(new Result[results.size()]); } }
Example #23
Source File: ScannerManager.java From attendee-checkin with Apache License 2.0 | 5 votes |
private String decode(byte[] data, int width, int height) { ScannerManager manager = mManager.get(); if (manager == null) { return null; } Rect rect = manager.getFramingRectInPreview(); PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.right, rect.bottom, false); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); QRCodeReader reader = new QRCodeReader(); try { Result result = reader.decode(bitmap, mHints); return result.getText(); } catch (ReaderException e) { // Ignore as we will repeatedly decode the preview frame return null; } }
Example #24
Source File: QRCodeMultiReader.java From weex with Apache License 2.0 | 5 votes |
@Override public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException { List<Result> results = new ArrayList<>(); DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); for (DetectorResult detectorResult : detectorResults) { try { DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints); ResultPoint[] points = detectorResult.getPoints(); // If the code was mirrored: swap the bottom-left and the top-right points. if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) { ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); List<byte[]> byteSegments = decoderResult.getByteSegments(); if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } String ecLevel = decoderResult.getECLevel(); if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } if (decoderResult.hasStructuredAppend()) { result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.getStructuredAppendSequenceNumber()); result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.getStructuredAppendParity()); } results.add(result); } catch (ReaderException re) { // ignore and continue } } if (results.isEmpty()) { return EMPTY_RESULT_ARRAY; } else { results = processStructuredAppend(results); return results.toArray(new Result[results.size()]); } }
Example #25
Source File: UPCEANExtensionSupport.java From reacteu-app with MIT License | 5 votes |
Result decodeRow(int rowNumber, BitArray row, int rowOffset) throws NotFoundException { int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN); try { return fiveSupport.decodeRow(rowNumber, row, extensionStartRange); } catch (ReaderException re) { return twoSupport.decodeRow(rowNumber, row, extensionStartRange); } }
Example #26
Source File: QRCodeMultiReader.java From barcodescanner-lib-aar with MIT License | 5 votes |
@Override public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException { List<Result> results = new ArrayList<>(); DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); for (DetectorResult detectorResult : detectorResults) { try { DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints); ResultPoint[] points = detectorResult.getPoints(); // If the code was mirrored: swap the bottom-left and the top-right points. if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) { ((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points); } Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); List<byte[]> byteSegments = decoderResult.getByteSegments(); if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } String ecLevel = decoderResult.getECLevel(); if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } if (decoderResult.hasStructuredAppend()) { result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.getStructuredAppendSequenceNumber()); result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.getStructuredAppendParity()); } results.add(result); } catch (ReaderException re) { // ignore and continue } } if (results.isEmpty()) { return EMPTY_RESULT_ARRAY; } else { results = processStructuredAppend(results); return results.toArray(new Result[results.size()]); } }
Example #27
Source File: MultiFormatOneDReader.java From reacteu-app with MIT License | 5 votes |
@Override public Result decodeRow(int rowNumber, BitArray row, Map<DecodeHintType,?> hints) throws NotFoundException { for (OneDReader reader : readers) { try { return reader.decodeRow(rowNumber, row, hints); } catch (ReaderException re) { // continue } } throw NotFoundException.getNotFoundInstance(); }
Example #28
Source File: UPCEANExtensionSupport.java From barcodescanner-lib-aar with MIT License | 5 votes |
Result decodeRow(int rowNumber, BitArray row, int rowOffset) throws NotFoundException { int[] extensionStartRange = UPCEANReader.findGuardPattern(row, rowOffset, false, EXTENSION_START_PATTERN); try { return fiveSupport.decodeRow(rowNumber, row, extensionStartRange); } catch (ReaderException ignored) { return twoSupport.decodeRow(rowNumber, row, extensionStartRange); } }
Example #29
Source File: QRCodeMultiReader.java From reacteu-app with MIT License | 5 votes |
@Override public Result[] decodeMultiple(BinaryBitmap image, Map<DecodeHintType,?> hints) throws NotFoundException { List<Result> results = new ArrayList<Result>(); DetectorResult[] detectorResults = new MultiDetector(image.getBlackMatrix()).detectMulti(hints); for (DetectorResult detectorResult : detectorResults) { try { DecoderResult decoderResult = getDecoder().decode(detectorResult.getBits(), hints); ResultPoint[] points = detectorResult.getPoints(); Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE); List<byte[]> byteSegments = decoderResult.getByteSegments(); if (byteSegments != null) { result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); } String ecLevel = decoderResult.getECLevel(); if (ecLevel != null) { result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); } results.add(result); } catch (ReaderException re) { // ignore and continue } } if (results.isEmpty()) { return EMPTY_RESULT_ARRAY; } else { return results.toArray(new Result[results.size()]); } }
Example #30
Source File: FragmentDecoder.java From camera2QRcodeReader with MIT License | 5 votes |
@Override public void onImageAvailable(ImageReader reader) { Log.e(TAG, "onImageAvailable: " + count++); Image img = null; img = reader.acquireLatestImage(); Result rawResult = null; try { if (img == null) throw new NullPointerException("cannot be null"); ByteBuffer buffer = img.getPlanes()[0].getBuffer(); byte[] data = new byte[buffer.remaining()]; buffer.get(data); int width = img.getWidth(); int height = img.getHeight(); PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); rawResult = mQrReader.decode(bitmap); onQRCodeRead(rawResult.getText()); } catch (ReaderException ignored) { Log.e(TAG, "Reader shows an exception! ", ignored); /* Ignored */ } catch (NullPointerException ex) { ex.printStackTrace(); } finally { mQrReader.reset(); Log.e(TAG, "in the finally! ------------"); if (img != null) img.close(); } if (rawResult != null) { Log.e(TAG, "Decoding successful!"); } else { Log.d(TAG, "No QR code found…"); } }