use of com.google.zxing.BinaryBitmap in project incubator-weex by apache.
the class DecodeHandler method decode.
/**
* Decode the data within the viewfinder rectangle, and time how long it took. For efficiency,
* reuse the same reader objects from one decode to the next.
*
* @param data The YUV preview frame.
* @param width The width of the preview frame.
* @param height The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
Result rawResult = null;
// PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
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;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);
if (source != null) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
Handler handler = activity.getHandler();
if (rawResult != null) {
// Don't log the barcode contents for security.
long end = System.currentTimeMillis();
Log.d(TAG, "Found barcode in " + (end - start) + " ms");
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult);
Bundle bundle = new Bundle();
bundleThumbnail(source, bundle);
message.setData(bundle);
message.sendToTarget();
}
} else {
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_failed);
message.sendToTarget();
}
}
}
use of com.google.zxing.BinaryBitmap in project keepass2android by PhilippC.
the class DecodeHandler method decode.
/**
* Decode the data within the viewfinder rectangle, and time how long it took. For efficiency,
* reuse the same reader objects from one decode to the next.
*
* @param data The YUV preview frame.
* @param width The width of the preview frame.
* @param height The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
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;
long start = System.currentTimeMillis();
Result rawResult = null;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
if (source != null) {
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// continue
} finally {
multiFormatReader.reset();
}
}
Handler handler = activity.getHandler();
if (rawResult != null) {
// Don't log the barcode contents for security.
long end = System.currentTimeMillis();
Log.d(TAG, "Found barcode in " + (end - start) + " ms");
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_succeeded, rawResult);
Bundle bundle = new Bundle();
bundleThumbnail(source, bundle);
message.setData(bundle);
message.sendToTarget();
}
} else {
if (handler != null) {
Message message = Message.obtain(handler, R.id.decode_failed);
message.sendToTarget();
}
}
}
use of com.google.zxing.BinaryBitmap in project titanium-barcode by mwaylabs.
the class DecodeThread method decode.
/**
* Decode the data within the viewfinder rectangle, and time how long it
* took. For efficiency, reuse the same reader objects from one decode to
* the next.
*
* @param data
* The YUV preview frame.
* @param width
* The width of the preview frame.
* @param height
* The height of the preview frame.
*/
private void decode(byte[] data, int width, int height) {
long start = System.currentTimeMillis();
Result rawResult = null;
PlanarYUVLuminanceSource source = CameraManager.get().buildLuminanceSource(data, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (ReaderException re) {
// Log and continue
Log.d("DecodeThread", re.toString());
} finally {
multiFormatReader.reset();
}
if (rawResult != null) {
long end = System.currentTimeMillis();
Log.v(TAG, "Found barcode (" + (end - start) + " ms):\n" + rawResult.toString());
Message message = Message.obtain(activity.getHandler(), Id.DECODE_SUCCEEDED, rawResult);
Bundle bundle = new Bundle();
bundle.putParcelable(BARCODE_BITMAP, source.renderCroppedGreyscaleBitmap());
message.setData(bundle);
message.sendToTarget();
} else {
Message message = Message.obtain(activity.getHandler(), Id.DECODE_FAILED);
message.sendToTarget();
}
}
use of com.google.zxing.BinaryBitmap in project QrCodeScanner by ekibun.
the class Decoder method decode.
public static Result decode(byte[] data, int width, int height, Rect crop) {
Result result = null;
try {
Hashtable<DecodeHintType, Object> hints = new Hashtable<>();
hints.put(DecodeHintType.CHARACTER_SET, "ISO-8859-1");
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
/*
Collection<BarcodeFormat> barcodeFormats = new ArrayList<>();
barcodeFormats.add(BarcodeFormat.QR_CODE);
barcodeFormats.add(BarcodeFormat.CODE_39);
barcodeFormats.add(BarcodeFormat.CODE_93);
barcodeFormats.add(BarcodeFormat.CODE_128);
hints.put(DecodeHintType.POSSIBLE_FORMATS, barcodeFormats);*/
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, crop.left, crop.top, crop.width(), crop.height(), false);
// BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
result = new QRCodeReader().decode(bitmap1, hints);
} catch (NotFoundException e) {
// e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
use of com.google.zxing.BinaryBitmap in project HL4A by HL4A.
the class 二维码 method 同步解析.
public static 返回值<String> 同步解析(Bitmap $图片) {
MultiFormatReader $解析器 = new MultiFormatReader();
// 解码的参数
Hashtable<DecodeHintType, Object> $设置 = new Hashtable<DecodeHintType, Object>(2);
// 可以解析的编码类型
无序集合<BarcodeFormat> $所有格式 = new 无序集合<BarcodeFormat>(反射.取所有枚举(BarcodeFormat.class));
$设置.put(DecodeHintType.POSSIBLE_FORMATS, $所有格式);
// 设置继续的字符编码格式为UTF8
// 设置.put(DecodeHintType.CHARACTER_SET, "UTF8");
// 设置解析配置参数
$解析器.setHints($设置);
try {
return 返回值.创建($解析器.decodeWithState(new BinaryBitmap(new HybridBinarizer(new 图片源码($图片)))).getText());
} catch (Exception $错误) {
return 返回值.创建(null, $错误);
}
}
Aggregations