Search in sources :

Example 1 with Image

use of net.sourceforge.zbar.Image in project SimplifyReader by chentao0707.

the class DecodeUtils method decodeWithZbar.

public String decodeWithZbar(Bitmap bitmap) {
    changeZBarDecodeDataMode();
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Image barcode = new Image(width, height, "Y800");
    int size = width * height;
    int[] pixels = new int[size];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    byte[] pixelsData = new byte[size];
    for (int i = 0; i < size; i++) {
        pixelsData[i] = (byte) pixels[i];
    }
    barcode.setData(pixelsData);
    int result = mImageScanner.scanImage(barcode);
    String resultStr = null;
    if (result != 0) {
        SymbolSet syms = mImageScanner.getResults();
        for (Symbol sym : syms) {
            resultStr = sym.getData();
        }
    }
    return resultStr;
}
Also used : SymbolSet(net.sourceforge.zbar.SymbolSet) Symbol(net.sourceforge.zbar.Symbol) Image(net.sourceforge.zbar.Image)

Example 2 with Image

use of net.sourceforge.zbar.Image in project barcodescanner by dm77.

the class ZBarScannerView 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) {
            byte[] rotatedData = new byte[data.length];
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) rotatedData[x * height + height - y - 1] = data[x + y * width];
            }
            int tmp = width;
            width = height;
            height = tmp;
            data = rotatedData;
        }
        Image barcode = new Image(width, height, "Y800");
        barcode.setData(data);
        int result = mScanner.scanImage(barcode);
        if (result != 0) {
            SymbolSet syms = mScanner.getResults();
            final Result rawResult = new Result();
            for (Symbol sym : syms) {
                // In order to retreive QR codes containing null bytes we need to
                // use getDataBytes() rather than getData() which uses C strings.
                // Weirdly ZBar transforms all data to UTF-8, even the data returned
                // by getDataBytes() so we have to decode it as UTF-8.
                String symData;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
                    symData = new String(sym.getDataBytes(), StandardCharsets.UTF_8);
                } else {
                    symData = sym.getData();
                }
                if (!TextUtils.isEmpty(symData)) {
                    rawResult.setContents(symData);
                    rawResult.setBarcodeFormat(BarcodeFormat.getFormatById(sym.getType()));
                    break;
                }
            }
            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(rawResult);
                    }
                }
            });
        } 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 : SymbolSet(net.sourceforge.zbar.SymbolSet) Symbol(net.sourceforge.zbar.Symbol) Handler(android.os.Handler) Image(net.sourceforge.zbar.Image) Camera(android.hardware.Camera)

Example 3 with Image

use of net.sourceforge.zbar.Image in project BGAQRCode-Android by bingoogolapple.

the class ZBarView method processData.

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

Example 4 with Image

use of net.sourceforge.zbar.Image in project SimplifyReader by chentao0707.

the class DecodeUtils method decodeWithZbar.

public String decodeWithZbar(byte[] data, int width, int height, Rect crop) {
    changeZBarDecodeDataMode();
    Image barcode = new Image(width, height, "Y800");
    barcode.setData(data);
    if (null != crop) {
        barcode.setCrop(crop.left, crop.top, crop.width(), crop.height());
    }
    int result = mImageScanner.scanImage(barcode);
    String resultStr = null;
    if (result != 0) {
        SymbolSet syms = mImageScanner.getResults();
        for (Symbol sym : syms) {
            resultStr = sym.getData();
        }
    }
    return resultStr;
}
Also used : SymbolSet(net.sourceforge.zbar.SymbolSet) Symbol(net.sourceforge.zbar.Symbol) Image(net.sourceforge.zbar.Image)

Aggregations

Image (net.sourceforge.zbar.Image)4 Symbol (net.sourceforge.zbar.Symbol)3 SymbolSet (net.sourceforge.zbar.SymbolSet)3 Rect (android.graphics.Rect)1 Camera (android.hardware.Camera)1 Handler (android.os.Handler)1