use of com.google.zxing.BinaryBitmap in project pancm_project by xuwujing.
the class QrCodeCreateUtil method readQrCode.
/**
* 读二维码并输出携带的信息
*/
public static void readQrCode(InputStream inputStream) throws IOException {
// 从输入流中获取字符串信息
BufferedImage image = ImageIO.read(inputStream);
// 将图像转换为二进制位图源
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
Result result = null;
try {
result = reader.decode(bitmap);
} catch (ReaderException e) {
e.printStackTrace();
}
System.out.println(result.getText());
}
use of com.google.zxing.BinaryBitmap in project elastic-core-maven by OrdinaryDude.
the class DecodeQRCode method processRequest.
@Override
protected JSONStreamAware processRequest(HttpServletRequest request) throws NxtException {
String qrCodeBase64 = Convert.nullToEmpty(request.getParameter("qrCodeBase64"));
JSONObject response = new JSONObject();
try {
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new ByteArrayInputStream(Base64.getDecoder().decode(qrCodeBase64))))));
Map hints = new HashMap();
hints.put(DecodeHintType.POSSIBLE_FORMATS, EnumSet.of(BarcodeFormat.QR_CODE));
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result qrCodeData = new MultiFormatReader().decode(binaryBitmap, hints);
response.put("qrCodeData", qrCodeData.getText());
} catch (IOException ex) {
String errorMessage = "Error reading base64 byte stream";
Logger.logErrorMessage(errorMessage, ex);
JSONData.putException(response, ex, errorMessage);
} catch (NullPointerException ex) {
String errorMessage = "Invalid base64 image";
Logger.logErrorMessage(errorMessage, ex);
JSONData.putException(response, ex, errorMessage);
} catch (NotFoundException ex) {
response.put("qrCodeData", "");
}
return response;
}
use of com.google.zxing.BinaryBitmap in project RxTools by vondear.
the class RxQrBarTool method decodeFromPhoto.
/**
* 解析图片中的 二维码 或者 条形码
*
* @param photo 待解析的图片
* @return Result 解析结果,解析识别时返回NULL
*/
public static Result decodeFromPhoto(Bitmap photo) {
Result rawResult = null;
if (photo != null) {
// 为防止原始图片过大导致内存溢出,这里先缩小原图显示,然后释放原始Bitmap占用的内存
Bitmap smallBitmap = RxImageTool.zoomBitmap(photo, photo.getWidth() / 2, photo.getHeight() / 2);
// 释放原始图片占用的内存,防止out of memory异常发生
photo.recycle();
MultiFormatReader multiFormatReader = new MultiFormatReader();
// 解码的参数
Hashtable<DecodeHintType, Object> hints = new Hashtable<>(2);
// 可以解析的编码类型
Vector<BarcodeFormat> decodeFormats = new Vector<>();
if (decodeFormats.isEmpty()) {
decodeFormats = new Vector<>();
Vector<BarcodeFormat> PRODUCT_FORMATS = new Vector<>(5);
PRODUCT_FORMATS.add(BarcodeFormat.UPC_A);
PRODUCT_FORMATS.add(BarcodeFormat.UPC_E);
PRODUCT_FORMATS.add(BarcodeFormat.EAN_13);
PRODUCT_FORMATS.add(BarcodeFormat.EAN_8);
// PRODUCT_FORMATS.add(BarcodeFormat.RSS14);
Vector<BarcodeFormat> ONE_D_FORMATS = new Vector<>(PRODUCT_FORMATS.size() + 4);
ONE_D_FORMATS.addAll(PRODUCT_FORMATS);
ONE_D_FORMATS.add(BarcodeFormat.CODE_39);
ONE_D_FORMATS.add(BarcodeFormat.CODE_93);
ONE_D_FORMATS.add(BarcodeFormat.CODE_128);
ONE_D_FORMATS.add(BarcodeFormat.ITF);
Vector<BarcodeFormat> QR_CODE_FORMATS = new Vector<>(1);
QR_CODE_FORMATS.add(BarcodeFormat.QR_CODE);
Vector<BarcodeFormat> DATA_MATRIX_FORMATS = new Vector<>(1);
DATA_MATRIX_FORMATS.add(BarcodeFormat.DATA_MATRIX);
// 这里设置可扫描的类型,我这里选择了都支持
decodeFormats.addAll(ONE_D_FORMATS);
decodeFormats.addAll(QR_CODE_FORMATS);
decodeFormats.addAll(DATA_MATRIX_FORMATS);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
// 设置继续的字符编码格式为UTF8
// hints.put(DecodeHintType.CHARACTER_SET, "UTF8");
// 设置解析配置参数
multiFormatReader.setHints(hints);
// 开始对图像资源解码
try {
rawResult = multiFormatReader.decodeWithState(new BinaryBitmap(new HybridBinarizer(new BitmapLuminanceSource(smallBitmap))));
} catch (Exception e) {
e.printStackTrace();
}
}
return rawResult;
}
use of com.google.zxing.BinaryBitmap in project portal by ixinportal.
the class parseQRCodeTool method parseQRCode.
public static String[] parseQRCode(InputStream imageInputStream) throws Exception {
BufferedImage image = ImageIO.read(imageInputStream);
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map<DecodeHintType, Object> hints = new HashMap<>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
MultiFormatReader formatReader = new MultiFormatReader();
Result result = formatReader.decode(binaryBitmap, hints);
String[] eInvoiceInfo = getEinvoiceInfo(result.getText());
return eInvoiceInfo;
}
use of com.google.zxing.BinaryBitmap in project react-native-camera by react-native-community.
the class BarCodeScannerAsyncTask method doInBackground.
@Override
protected Result doInBackground(Void... ignored) {
if (isCancelled() || mDelegate == null) {
return null;
}
Result result = null;
try {
BinaryBitmap bitmap = generateBitmapFromImageData(mImageData, mWidth, mHeight);
result = mMultiFormatReader.decodeWithState(bitmap);
} catch (NotFoundException e) {
// No barcode found, result is already null.
} catch (Throwable t) {
t.printStackTrace();
}
return result;
}
Aggregations