use of com.google.zxing.qrcode.QRCodeReader in project weex-example by KalicyZhou.
the class MultiFormatReader method setHints.
/**
* This method adds state to the MultiFormatReader. By setting the hints once, subsequent calls
* to decodeWithState(image) can reuse the same set of readers without reallocating memory. This
* is important for performance in continuous scan clients.
*
* @param hints The set of hints to use for subsequent calls to decode(image)
*/
public void setHints(Map<DecodeHintType, ?> hints) {
this.hints = hints;
boolean tryHarder = hints != null && hints.containsKey(DecodeHintType.TRY_HARDER);
@SuppressWarnings("unchecked") Collection<BarcodeFormat> formats = hints == null ? null : (Collection<BarcodeFormat>) hints.get(DecodeHintType.POSSIBLE_FORMATS);
Collection<Reader> readers = new ArrayList<Reader>();
if (formats != null) {
boolean addOneDReader = formats.contains(BarcodeFormat.UPC_A) || formats.contains(BarcodeFormat.UPC_E) || formats.contains(BarcodeFormat.EAN_13) || formats.contains(BarcodeFormat.EAN_8) || formats.contains(BarcodeFormat.CODABAR) || formats.contains(BarcodeFormat.CODE_39) || formats.contains(BarcodeFormat.CODE_93) || formats.contains(BarcodeFormat.CODE_128) || formats.contains(BarcodeFormat.ITF) || formats.contains(BarcodeFormat.RSS_14) || formats.contains(BarcodeFormat.RSS_EXPANDED);
// Put 1D readers upfront in "normal" mode
if (addOneDReader && !tryHarder) {
readers.add(new MultiFormatOneDReader(hints));
}
if (formats.contains(BarcodeFormat.QR_CODE)) {
readers.add(new QRCodeReader());
}
if (formats.contains(BarcodeFormat.DATA_MATRIX)) {
readers.add(new DataMatrixReader());
}
if (formats.contains(BarcodeFormat.AZTEC)) {
readers.add(new AztecReader());
}
if (formats.contains(BarcodeFormat.PDF_417)) {
readers.add(new PDF417Reader());
}
if (formats.contains(BarcodeFormat.MAXICODE)) {
readers.add(new MaxiCodeReader());
}
// At end in "try harder" mode
if (addOneDReader && tryHarder) {
readers.add(new MultiFormatOneDReader(hints));
}
}
if (readers.isEmpty()) {
if (!tryHarder) {
readers.add(new MultiFormatOneDReader(hints));
}
readers.add(new QRCodeReader());
readers.add(new DataMatrixReader());
readers.add(new AztecReader());
readers.add(new PDF417Reader());
readers.add(new MaxiCodeReader());
if (tryHarder) {
readers.add(new MultiFormatOneDReader(hints));
}
}
this.readers = readers.toArray(new Reader[readers.size()]);
}
use of com.google.zxing.qrcode.QRCodeReader in project SmartMesh_Android by SmartMeshFoundation.
the class CaptureActivity method scanningImage.
/**
* Scan the qr code image method
*/
public Result scanningImage(String path) {
if (TextUtils.isEmpty(path)) {
return null;
}
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
// Set the qr code coding content
hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
BitmapFactory.Options options = new BitmapFactory.Options();
// To obtain the original size
options.inJustDecodeBounds = true;
scanBitmap = BitmapFactory.decodeFile(path, options);
// To get the new size
options.inJustDecodeBounds = false;
int sampleSize = (int) (options.outHeight / (float) 200);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
scanBitmap = BitmapFactory.decodeFile(path, options);
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
return reader.decode(bitmap1, hints);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
return null;
}
use of com.google.zxing.qrcode.QRCodeReader in project summer-android by cn-cerc.
the class FrmScanBarcode method scanningImage.
/**
* 识别二维码图片中的数据
*
* @param path
* @return
*/
public Result scanningImage(String path) {
if (TextUtils.isEmpty(path)) {
return null;
}
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
// 设置二维码内容的编码
hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
BitmapFactory.Options options = new BitmapFactory.Options();
// 先获取原大小
options.inJustDecodeBounds = true;
scanBitmap = BitmapFactory.decodeFile(path, options);
// 获取新的大小
options.inJustDecodeBounds = false;
int sampleSize = (int) (options.outHeight / (float) 200);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
scanBitmap = BitmapFactory.decodeFile(path, options);
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
return reader.decode(bitmap1, hints);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
return null;
}
use of com.google.zxing.qrcode.QRCodeReader in project CodenameOne by codenameone.
the class SnapshotThread method run.
public void run() {
do {
waitForSignal();
if (done) {
break;
}
BinaryBitmap bitmap = null;
try {
Player player = barCodeScanner.getPlayer();
if (player == null) {
break;
}
multimediaManager.setFocus(player);
byte[] snapshot = takeSnapshot();
if (snapshot == null) {
break;
}
Image capturedImage = Image.createImage(snapshot, 0, snapshot.length);
LuminanceSource source = new CN1ImageLuminanceSource(capturedImage);
bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = null;
if (barCodeScanner.type == BarCodeScanner.QRCODE) {
Reader reader = new QRCodeReader();
result = reader.decode(bitmap);
} else {
MultiFormatReader reader = new MultiFormatReader();
result = reader.decodeBarcode(bitmap);
}
barCodeScanner.handleDecodedText(result);
} catch (ReaderException re) {
barCodeScanner.showError("Not found!");
} catch (Exception e) {
barCodeScanner.showError(e.getMessage());
}
} while (!done);
}
use of com.google.zxing.qrcode.QRCodeReader in project QRCode by 5peak2me.
the class MipcaActivityCapture method scanningImage.
/**
* 扫描二维码图片的方法
* @param path
* @return
*/
public Result scanningImage(String path) {
if (TextUtils.isEmpty(path)) {
return null;
}
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
// 设置二维码内容的编码
hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
BitmapFactory.Options options = new BitmapFactory.Options();
// 先获取原大小
options.inJustDecodeBounds = true;
scanBitmap = BitmapFactory.decodeFile(path, options);
// 获取新的大小
options.inJustDecodeBounds = false;
int sampleSize = (int) (options.outHeight / (float) 200);
if (sampleSize <= 0)
sampleSize = 1;
options.inSampleSize = sampleSize;
scanBitmap = BitmapFactory.decodeFile(path, options);
RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
return reader.decode(bitmap1, hints);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
return null;
}
Aggregations