Search in sources :

Example 1 with ScanResult

use of cn.bingoogolapple.qrcode.core.ScanResult in project BGAQRCode-Android by bingoogolapple.

the class ZBarView method processData.

@Override
protected ScanResult processData(byte[] data, int width, int height, boolean isRetry) {
    Image barcode = new Image(width, height, "Y800");
    Rect scanBoxAreaRect = mScanBoxView.getScanBoxAreaRect(height);
    if (scanBoxAreaRect != null && !isRetry && scanBoxAreaRect.left + scanBoxAreaRect.width() <= width && scanBoxAreaRect.top + scanBoxAreaRect.height() <= height) {
        barcode.setCrop(scanBoxAreaRect.left, scanBoxAreaRect.top, scanBoxAreaRect.width(), scanBoxAreaRect.height());
    }
    barcode.setData(data);
    String result = processData(barcode);
    return new ScanResult(result);
}
Also used : Rect(android.graphics.Rect) ScanResult(cn.bingoogolapple.qrcode.core.ScanResult) Image(net.sourceforge.zbar.Image)

Example 2 with ScanResult

use of cn.bingoogolapple.qrcode.core.ScanResult in project BGAQRCode-Android by bingoogolapple.

the class ZBarView method processBitmapData.

@Override
protected ScanResult processBitmapData(Bitmap bitmap) {
    try {
        int picWidth = bitmap.getWidth();
        int picHeight = bitmap.getHeight();
        Image barcode = new Image(picWidth, picHeight, "RGB4");
        int[] pix = new int[picWidth * picHeight];
        bitmap.getPixels(pix, 0, picWidth, 0, 0, picWidth, picHeight);
        barcode.setData(pix);
        String result = processData(barcode.convert("Y800"));
        return new ScanResult(result);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ScanResult(cn.bingoogolapple.qrcode.core.ScanResult) Image(net.sourceforge.zbar.Image)

Example 3 with ScanResult

use of cn.bingoogolapple.qrcode.core.ScanResult in project BGAQRCode-Android by bingoogolapple.

the class ZXingView method processData.

@Override
protected ScanResult processData(byte[] data, int width, int height, boolean isRetry) {
    Result rawResult = null;
    Rect scanBoxAreaRect = null;
    try {
        PlanarYUVLuminanceSource source;
        scanBoxAreaRect = mScanBoxView.getScanBoxAreaRect(height);
        if (scanBoxAreaRect != null) {
            source = new PlanarYUVLuminanceSource(data, width, height, scanBoxAreaRect.left, scanBoxAreaRect.top, scanBoxAreaRect.width(), scanBoxAreaRect.height(), false);
        } else {
            source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        }
        rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new GlobalHistogramBinarizer(source)));
        if (rawResult == null) {
            rawResult = mMultiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(source)));
            if (rawResult != null) {
                BGAQRCodeUtil.d("GlobalHistogramBinarizer 没识别到,HybridBinarizer 能识别到");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        mMultiFormatReader.reset();
    }
    if (rawResult == null) {
        return null;
    }
    String result = rawResult.getText();
    if (TextUtils.isEmpty(result)) {
        return null;
    }
    BarcodeFormat barcodeFormat = rawResult.getBarcodeFormat();
    BGAQRCodeUtil.d("格式为:" + barcodeFormat.name());
    // 处理自动缩放和定位点
    boolean isNeedAutoZoom = isNeedAutoZoom(barcodeFormat);
    if (isShowLocationPoint() || isNeedAutoZoom) {
        ResultPoint[] resultPoints = rawResult.getResultPoints();
        final PointF[] pointArr = new PointF[resultPoints.length];
        int pointIndex = 0;
        for (ResultPoint resultPoint : resultPoints) {
            pointArr[pointIndex] = new PointF(resultPoint.getX(), resultPoint.getY());
            pointIndex++;
        }
        if (transformToViewCoordinates(pointArr, scanBoxAreaRect, isNeedAutoZoom, result)) {
            return null;
        }
    }
    return new ScanResult(result);
}
Also used : GlobalHistogramBinarizer(com.google.zxing.common.GlobalHistogramBinarizer) Rect(android.graphics.Rect) ScanResult(cn.bingoogolapple.qrcode.core.ScanResult) ResultPoint(com.google.zxing.ResultPoint) BarcodeFormat(com.google.zxing.BarcodeFormat) PointF(android.graphics.PointF) HybridBinarizer(com.google.zxing.common.HybridBinarizer) ResultPoint(com.google.zxing.ResultPoint) Result(com.google.zxing.Result) ScanResult(cn.bingoogolapple.qrcode.core.ScanResult) PlanarYUVLuminanceSource(com.google.zxing.PlanarYUVLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap)

Aggregations

ScanResult (cn.bingoogolapple.qrcode.core.ScanResult)3 Rect (android.graphics.Rect)2 Image (net.sourceforge.zbar.Image)2 PointF (android.graphics.PointF)1 BarcodeFormat (com.google.zxing.BarcodeFormat)1 BinaryBitmap (com.google.zxing.BinaryBitmap)1 PlanarYUVLuminanceSource (com.google.zxing.PlanarYUVLuminanceSource)1 Result (com.google.zxing.Result)1 ResultPoint (com.google.zxing.ResultPoint)1 GlobalHistogramBinarizer (com.google.zxing.common.GlobalHistogramBinarizer)1 HybridBinarizer (com.google.zxing.common.HybridBinarizer)1