use of net.sourceforge.zbar.SymbolSet 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) {
int rotationCount = getRotationCount();
if (rotationCount == 1 || rotationCount == 3) {
int tmp = width;
width = height;
height = tmp;
}
data = getRotatedData(data, camera);
}
Rect rect = getFramingRectInPreview(width, height);
Image barcode = new Image(width, height, "Y800");
barcode.setData(data);
barcode.setCrop(rect.left, rect.top, rect.width(), rect.height());
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);
}
}
use of net.sourceforge.zbar.SymbolSet in project samourai-wallet-android by Samourai-Wallet.
the class ZBarScannerActivity method onPreviewFrame.
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = mScanner.scanImage(barcode);
if (result != 0) {
mCamera.cancelAutoFocus();
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mPreviewing = false;
SymbolSet syms = mScanner.getResults();
for (Symbol sym : syms) {
String symData = sym.getData();
if (!TextUtils.isEmpty(symData)) {
Intent dataIntent = new Intent();
dataIntent.putExtra(SCAN_RESULT, symData);
dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
setResult(Activity.RESULT_OK, dataIntent);
finish();
break;
}
}
}
}
use of net.sourceforge.zbar.SymbolSet 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;
}
use of net.sourceforge.zbar.SymbolSet in project sentinel-android by Samourai-Wallet.
the class ZBarScannerActivity method onPreviewFrame.
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Camera.Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = mScanner.scanImage(barcode);
if (result != 0) {
mCamera.cancelAutoFocus();
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
mPreviewing = false;
SymbolSet syms = mScanner.getResults();
for (Symbol sym : syms) {
String symData = sym.getData();
if (!TextUtils.isEmpty(symData)) {
Intent dataIntent = new Intent();
dataIntent.putExtra(SCAN_RESULT, symData);
dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
setResult(Activity.RESULT_OK, dataIntent);
finish();
break;
}
}
}
}
use of net.sourceforge.zbar.SymbolSet 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;
}