use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project pancm_project by xuwujing.
the class QrCodeMaxTest method decode.
// qrcode 解码
static void decode(String file) {
try {
Result result = null;
BufferedImage image = null;
image = ImageIO.read(new File(file));
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
result = new MultiFormatReader().decode(bitmap, hints);
String rtn = result.getText();
System.out.println(rtn);
System.out.println(rtn.length());
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project pancm_project by xuwujing.
the class QrCodeCreateUtil method readQrCode.
/**
* 读二维码并输出携带的信息
*
* @param inputStream the input stream
* @throws IOException the io exception
*/
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.client.j2se.BufferedImageLuminanceSource in project camel by apache.
the class BarcodeDataFormat method readImage.
/**
* Reads the message from a code.
*/
private String readImage(final Exchange exchange, final InputStream stream) throws Exception {
final MultiFormatReader reader = new MultiFormatReader();
final BufferedInputStream in = exchange.getContext().getTypeConverter().mandatoryConvertTo(BufferedInputStream.class, stream);
final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(in))));
final Result result = reader.decode(bitmap, readerHintMap);
// write the found barcode format into the header
exchange.getOut().setHeader(Barcode.BARCODE_FORMAT, result.getBarcodeFormat());
return result.getText();
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project camel by apache.
the class BarcodeTestBase method checkFormat.
private void checkFormat(File file, BarcodeFormat format) throws IOException {
Reader reader = new MultiFormatReader();
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(file))));
Result result;
try {
result = reader.decode(bitmap);
} catch (ReaderException ex) {
throw new IOException(ex);
}
assertEquals(format, result.getBarcodeFormat());
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project portal by ixinportal.
the class parseQRCodeTool method parseQRCode.
/**
* 解析指定路径下的二维码图片
*
* @param filePath 二维码图片路径
* @return
*/
public static String[] parseQRCode(File PDFImageFile) throws Exception {
BufferedImage image = ImageIO.read(PDFImageFile);
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;
}
Aggregations