Search in sources :

Example 6 with QRCodeReader

use of com.google.zxing.qrcode.QRCodeReader in project weex-example by KalicyZhou.

the class MultiFormatReader method setHints.

/**
   * This method adds state to the MultiFormatReader. By setting the hints once, subsequent calls
   * to decodeWithState(image) can reuse the same set of readers without reallocating memory. This
   * is important for performance in continuous scan clients.
   *
   * @param hints The set of hints to use for subsequent calls to decode(image)
   */
public void setHints(Map<DecodeHintType, ?> hints) {
    this.hints = hints;
    boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
    @SuppressWarnings("unchecked") Collection<BarcodeFormat> formats = hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
    Collection<Reader> readers = new ArrayList<Reader>();
    if (formats != null) {
        boolean addOneDReader = formats.contains(BarcodeFormat.UPC_A) || formats.contains(BarcodeFormat.UPC_E) || formats.contains(BarcodeFormat.EAN_13) || formats.contains(BarcodeFormat.EAN_8) || formats.contains(BarcodeFormat.CODABAR) || formats.contains(BarcodeFormat.CODE_39) || formats.contains(BarcodeFormat.CODE_93) || formats.contains(BarcodeFormat.CODE_128) || formats.contains(BarcodeFormat.ITF) || formats.contains(BarcodeFormat.RSS_14) || formats.contains(BarcodeFormat.RSS_EXPANDED);
        // Put 1D readers upfront in "normal" mode
        if (addOneDReader && !tryHarder) {
            readers.add(new MultiFormatOneDReader(hints));
        }
        if (formats.contains(BarcodeFormat.QR_CODE)) {
            readers.add(new QRCodeReader());
        }
        if (formats.contains(BarcodeFormat.DATA_MATRIX)) {
            readers.add(new DataMatrixReader());
        }
        if (formats.contains(BarcodeFormat.AZTEC)) {
            readers.add(new AztecReader());
        }
        if (formats.contains(BarcodeFormat.PDF_417)) {
            readers.add(new PDF417Reader());
        }
        if (formats.contains(BarcodeFormat.MAXICODE)) {
            readers.add(new MaxiCodeReader());
        }
        // At end in "try harder" mode
        if (addOneDReader && tryHarder) {
            readers.add(new MultiFormatOneDReader(hints));
        }
    }
    if (readers.isEmpty()) {
        if (!tryHarder) {
            readers.add(new MultiFormatOneDReader(hints));
        }
        readers.add(new QRCodeReader());
        readers.add(new DataMatrixReader());
        readers.add(new AztecReader());
        readers.add(new PDF417Reader());
        readers.add(new MaxiCodeReader());
        if (tryHarder) {
            readers.add(new MultiFormatOneDReader(hints));
        }
    }
    this.readers = readers.toArray(new Reader[readers.size()]);
}
Also used : QRCodeReader(com.google.zxing.qrcode.QRCodeReader) DataMatrixReader(com.google.zxing.datamatrix.DataMatrixReader) AztecReader(com.google.zxing.aztec.AztecReader) ArrayList(java.util.ArrayList) MaxiCodeReader(com.google.zxing.maxicode.MaxiCodeReader) AztecReader(com.google.zxing.aztec.AztecReader) DataMatrixReader(com.google.zxing.datamatrix.DataMatrixReader) MultiFormatOneDReader(com.google.zxing.oned.MultiFormatOneDReader) PDF417Reader(com.google.zxing.pdf417.PDF417Reader) QRCodeReader(com.google.zxing.qrcode.QRCodeReader) MultiFormatOneDReader(com.google.zxing.oned.MultiFormatOneDReader) PDF417Reader(com.google.zxing.pdf417.PDF417Reader) MaxiCodeReader(com.google.zxing.maxicode.MaxiCodeReader)

Example 7 with QRCodeReader

use of com.google.zxing.qrcode.QRCodeReader 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 8 with QRCodeReader

use of com.google.zxing.qrcode.QRCodeReader 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)

Example 9 with QRCodeReader

use of com.google.zxing.qrcode.QRCodeReader in project CodenameOne by codenameone.

the class SnapshotThread method run.

public void run() {
    do {
        waitForSignal();
        if (done) {
            break;
        }
        BinaryBitmap bitmap = null;
        try {
            Player player = barCodeScanner.getPlayer();
            if (player == null) {
                break;
            }
            multimediaManager.setFocus(player);
            byte[] snapshot = takeSnapshot();
            if (snapshot == null) {
                break;
            }
            Image capturedImage = Image.createImage(snapshot, 0, snapshot.length);
            LuminanceSource source = new CN1ImageLuminanceSource(capturedImage);
            bitmap = new BinaryBitmap(new HybridBinarizer(source));
            Result result = null;
            if (barCodeScanner.type == BarCodeScanner.QRCODE) {
                Reader reader = new QRCodeReader();
                result = reader.decode(bitmap);
            } else {
                MultiFormatReader reader = new MultiFormatReader();
                result = reader.decodeBarcode(bitmap);
            }
            barCodeScanner.handleDecodedText(result);
        } catch (ReaderException re) {
            barCodeScanner.showError("Not found!");
        } catch (Exception e) {
            barCodeScanner.showError(e.getMessage());
        }
    } while (!done);
}
Also used : QRCodeReader(com.google.zxing.qrcode.QRCodeReader) Player(javax.microedition.media.Player) QRCodeReader(com.google.zxing.qrcode.QRCodeReader) Image(com.codename1.ui.Image) HybridBinarizer(com.google.zxing.common.HybridBinarizer) MediaException(javax.microedition.media.MediaException)

Example 10 with QRCodeReader

use of com.google.zxing.qrcode.QRCodeReader in project QRCode by 5peak2me.

the class MipcaActivityCapture 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(com.google.zxing.zxing.image.RGBLuminanceSource)

Aggregations

QRCodeReader (com.google.zxing.qrcode.QRCodeReader)14 HybridBinarizer (com.google.zxing.common.HybridBinarizer)10 BinaryBitmap (com.google.zxing.BinaryBitmap)8 DecodeHintType (com.google.zxing.DecodeHintType)6 NotFoundException (com.google.zxing.NotFoundException)4 BufferedImageLuminanceSource (com.google.zxing.client.j2se.BufferedImageLuminanceSource)4 Hashtable (java.util.Hashtable)4 BitmapFactory (android.graphics.BitmapFactory)3 ChecksumException (com.google.zxing.ChecksumException)3 FormatException (com.google.zxing.FormatException)3 AztecReader (com.google.zxing.aztec.AztecReader)3 DataMatrixReader (com.google.zxing.datamatrix.DataMatrixReader)3 MaxiCodeReader (com.google.zxing.maxicode.MaxiCodeReader)3 MultiFormatOneDReader (com.google.zxing.oned.MultiFormatOneDReader)3 PDF417Reader (com.google.zxing.pdf417.PDF417Reader)3 BufferedImage (java.awt.image.BufferedImage)3 ArrayList (java.util.ArrayList)3 Result (com.google.zxing.Result)2 IndexController (alfio.controller.IndexController)1 AdditionalServiceApiController (alfio.controller.api.admin.AdditionalServiceApiController)1