com.google.zxing.Reader Java Examples

The following examples show how to use com.google.zxing.Reader. 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: BarcodeScanCameraActivity.java    From android-opensource-library-56 with Apache License 2.0 6 votes vote down vote up
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    int previewWidth = camera.getParameters().getPreviewSize().width;
    int previewHeight = camera.getParameters().getPreviewSize().height;

    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(
            data, previewWidth, previewHeight, 0, 0, previewWidth,
            previewHeight, false);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    Reader reader = new QRCodeReader();
    try {

        Result result = reader.decode(bitmap);
        String text = result.getText();

        Intent intent = new Intent();
        intent.setData(Uri.parse(text));
        setResult(RESULT_OK, intent);
        finish();
    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "Not Found",
                Toast.LENGTH_SHORT).show();
    }
}
 
Example #2
Source File: QrCodeHelper.java    From adamant-android with GNU General Public License v3.0 5 votes vote down vote up
public String parse(InputStream imageStream) {
    final Bitmap bMap = BitmapFactory.decodeStream(imageStream);
    String contents = null;

    int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];
    bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());

    LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(), intArray);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

    Map<DecodeHintType, Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(
            DecodeHintType.class);
    tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS,
            EnumSet.allOf(BarcodeFormat.class));
    tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);

    Reader reader = new MultiFormatReader();
    Result result = null;
    try {
        result = reader.decode(bitmap, tmpHintsMap);
        contents = result.getText();
    } catch (NotFoundException | ChecksumException | FormatException e) {
        e.printStackTrace();
    }

    return contents;
}
 
Example #3
Source File: MainActivity.java    From Aegis with GNU General Public License v3.0 5 votes vote down vote up
private void onScanImageResult(Intent intent) {
    Uri inputFile = (intent.getData());
    Bitmap bitmap;

    try {
        BitmapFactory.Options bmOptions = new BitmapFactory.Options();

        try (InputStream inputStream = getContentResolver().openInputStream(inputFile)) {
            bitmap = BitmapFactory.decodeStream(inputStream, null, bmOptions);
        }

        int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
        bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());

        LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));

        Reader reader = new MultiFormatReader();
        Result result = reader.decode(binaryBitmap);

        GoogleAuthInfo info = GoogleAuthInfo.parseUri(result.getText());
        VaultEntry entry = new VaultEntry(info);

        startEditEntryActivity(CODE_ADD_ENTRY, entry, true);
    } catch (NotFoundException | IOException | ChecksumException | FormatException | GoogleAuthInfoException e) {
        e.printStackTrace();
        Dialogs.showErrorDialog(this, R.string.unable_to_read_qrcode, e);
    }
}
 
Example #4
Source File: GenericMultipleBarcodeReader.java    From reacteu-app with MIT License 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #5
Source File: MultiFormatUPCEANReader.java    From weex with Apache License 2.0 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}
 
Example #6
Source File: GenericMultipleBarcodeReader.java    From weex with Apache License 2.0 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #7
Source File: ByQuadrantReader.java    From weex with Apache License 2.0 4 votes vote down vote up
public ByQuadrantReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #8
Source File: MultiFormatOneDReader.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}
 
Example #9
Source File: MultiFormatUPCEANReader.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}
 
Example #10
Source File: GenericMultipleBarcodeReader.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #11
Source File: ByQuadrantReader.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
public ByQuadrantReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #12
Source File: MultiFormatOneDReader.java    From reacteu-app with MIT License 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}
 
Example #13
Source File: MultiFormatUPCEANReader.java    From reacteu-app with MIT License 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}
 
Example #14
Source File: ByQuadrantReader.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
public ByQuadrantReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #15
Source File: ByQuadrantReader.java    From reacteu-app with MIT License 4 votes vote down vote up
public ByQuadrantReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #16
Source File: GenericMultipleBarcodeReader.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader reader)
{
    b = reader;
}
 
Example #17
Source File: ByQuadrantReader.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public ByQuadrantReader(Reader reader)
{
    a = reader;
}
 
Example #18
Source File: MultiFormatOneDReader.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
@Override
public void reset() {
	for (Reader reader : readers) {
		reader.reset();
	}
}
 
Example #19
Source File: MultiFormatUPCEANReader.java    From RipplePower with Apache License 2.0 4 votes vote down vote up
@Override
public void reset() {
	for (Reader reader : readers) {
		reader.reset();
	}
}
 
Example #20
Source File: SymbolTest.java    From OkapiBarcode with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a ZXing reader that can read the specified symbol.
 *
 * @param symbol the symbol to be read
 * @return a ZXing reader that can read the specified symbol
 */
private static Reader findReader(Symbol symbol) {

    // TODO: see if we can massage data enough to check MaxiCode symbols against MaxiCodeReader instances

    if (symbol instanceof Code128 || symbol instanceof UspsPackage) {
        return new Code128Reader();
    } else if (symbol instanceof Code93) {
        return new Code93Reader();
    } else if (symbol instanceof Code3Of9) {
        return new Code39Reader();
    } else if (symbol instanceof Codabar) {
        return new CodaBarReader();
    } else if (symbol instanceof AztecCode &&
               symbol.getDataType() != DataType.GS1 &&
               symbol.getEciMode() == 3 &&
              !symbol.getReaderInit() &&
              !symbol.getContent().isEmpty()) {
        // ZXing does not currently support GS1 in Aztec Code symbols
        // ZXing does not currently support ECI in Aztec Code symbols
        // ZXing does not currently support reader initialization in Aztec Code symbols
        // ZXing cannot find symbols if they don't contain any actual data
        return new AztecReader();
    } else if (symbol instanceof QrCode) {
        return new QRCodeReader();
    } else if (symbol instanceof DataMatrix &&
               symbol.getEciMode() == 3 &&
               ((DataMatrix) symbol).getStructuredAppendTotal() == 1) {
        // ZXing does not currently support ECI in Data Matrix symbols
        // ZXing does not currently support Structured Append in Data Matrix symbols
        return new DataMatrixReader();
    } else if (symbol instanceof Ean) {
        Ean ean = (Ean) symbol;
        if (ean.getMode() == Ean.Mode.EAN8) {
            return new EAN8Reader();
        } else {
            return new EAN13Reader();
        }
    } else if (symbol instanceof Pdf417) {
        Pdf417 pdf417 = (Pdf417) symbol;
        if (pdf417.getMode() != Pdf417.Mode.MICRO) {
            return new PDF417Reader();
        }
    } else if (symbol instanceof Upc) {
        Upc upc = (Upc) symbol;
        if (upc.getMode() == Upc.Mode.UPCA) {
            return new UPCAReader();
        } else {
            return new UPCEReader();
        }
    } else if (symbol instanceof DataBarExpanded) {
        return new RSSExpandedReader();
    } else if (symbol instanceof DataBar14 && !((DataBar14) symbol).getLinkageFlag()) {
        return new RSS14Reader();
    }

    // no corresponding ZXing reader exists, or it behaves badly so we don't use it for testing
    return null;
}
 
Example #21
Source File: GenericMultipleBarcodeReader.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #22
Source File: ByQuadrantReader.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public ByQuadrantReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #23
Source File: GenericMultipleBarcodeReader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #24
Source File: ByQuadrantReader.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public ByQuadrantReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #25
Source File: GenericMultipleBarcodeReader.java    From QrCodeScanner with GNU General Public License v3.0 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #26
Source File: MultiFormatOneDReader.java    From ScreenCapture with MIT License 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}
 
Example #27
Source File: MultiFormatUPCEANReader.java    From ScreenCapture with MIT License 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}
 
Example #28
Source File: GenericMultipleBarcodeReader.java    From ScreenCapture with MIT License 4 votes vote down vote up
public GenericMultipleBarcodeReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #29
Source File: ByQuadrantReader.java    From ScreenCapture with MIT License 4 votes vote down vote up
public ByQuadrantReader(Reader delegate) {
  this.delegate = delegate;
}
 
Example #30
Source File: MultiFormatOneDReader.java    From Tesseract-OCR-Scanner with Apache License 2.0 4 votes vote down vote up
@Override
public void reset() {
  for (Reader reader : readers) {
    reader.reset();
  }
}