net.sourceforge.zbar.Image Java Examples

The following examples show how to use net.sourceforge.zbar.Image. 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: ZbarController.java    From qrcode_android with GNU Lesser General Public License v3.0 6 votes vote down vote up
public String scan(byte[] data, int width, int height) {
    if (data == null || width <= 0 || height <= 0) {
        return null;
    }

    Image image = new Image(width, height, "Y800");
    image.setData(data);

    int result = scanner.scanImage(image);

    if (result != 0) {
        SymbolSet syms = scanner.getResults();
        for (Symbol sym : syms) {
            return sym.getData();
        }
    }
    return null;
}
 
Example #2
Source File: ZBarDecoder.java    From react-native-barcode with MIT License 6 votes vote down vote up
@Override
public ReadableMap decodeRGBBitmap(Bitmap bitmap) {
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    int[] pixels = new int[width * height];
    bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
    bitmap.recycle();

    Image image = new Image(width, height, ImageFormat.RGB4.toString());
    image.setData(pixels);
    image = image.convert(ImageFormat.Y800.toString());

    WritableMap result = null;
    if (mScanner.scanImage(image) != 0) {
        SymbolSet symbols = mScanner.getResults();
        Symbol symbol = symbols.iterator().next();
        result = Arguments.createMap();
        result.putInt("format", symbolToFormat(symbol.getType()));
        result.putString("content", fixEncoding(symbol.getData()));
    }
    return result;
}
 
Example #3
Source File: ZBarDecoder.java    From react-native-barcode with MIT License 6 votes vote down vote up
@Override
public WritableMap decodeNV21Data(byte[] data, int width, int height, int rotation) {
    Image image = new Image(width, height, ImageFormat.Y800.toString());
    image.setData(data);

    WritableMap result = null;
    if (mScanner.scanImage(image) != 0) {
        SymbolSet symbols = mScanner.getResults();
        Symbol symbol = symbols.iterator().next();
        result = Arguments.createMap();
        result.putInt("format", symbolToFormat(symbol.getType()));
        result.putString("content", fixEncoding(symbol.getData()));
    }
    image.destroy();
    return result;
}
 
Example #4
Source File: DecodeUtils.java    From SimplifyReader with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: DecodeUtils.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
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;
}