use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project DevKits by qmjy.
the class CodecFrame method run.
@Override
public void run() {
do {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
LOGGER.info("Sleep failed in recognize QR code...");
}
if (webcam != null) {
BufferedImage image = null;
if (webcam.isOpen()) {
if ((image = webcam.getImage()) == null) {
continue;
}
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
Result result = new MultiFormatReader().decode(bitmap);
if (result != null) {
DKSystemUtil.playSound(DKSystemUtil.SOUND_TYPE_SCAN);
String resultTxt = "<html>Recognized result as below has been set to the clipboard:<br/><span style='color:RED'>";
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable tText = new StringSelection(result.getText());
clip.setContents(tText, null);
JOptionPane.showMessageDialog(this, resultTxt + result.getText() + "</span></html>", "QR Recognize Result", JOptionPane.INFORMATION_MESSAGE);
}
} catch (NotFoundException e) {
LOGGER.info("Recognize QR Code from camera...");
}
}
}
} while (true);
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project mica by lets-mica.
the class QrCode method read.
/**
* 从指定的 QRCode 图像对象中解析出其内容。
*
* @param qrCodeImage QRCode 图像对象
* @param hints hints
* @return QRCode 中的内容
*/
public static String read(BufferedImage qrCodeImage, Map<DecodeHintType, ?> hints) {
LuminanceSource source = new BufferedImageLuminanceSource(qrCodeImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
Result result = new QRCodeReader().decode(bitmap, hints);
return result.getText();
} catch (NotFoundException | ChecksumException | FormatException e) {
throw Exceptions.unchecked(e);
} finally {
qrCodeImage.getGraphics().dispose();
}
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project vividus by vividus-framework.
the class BarcodeActions method scanBarcode.
public String scanBarcode(BufferedImage barcode) throws NotFoundException {
LuminanceSource source = new BufferedImageLuminanceSource(barcode);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = new MultiFormatReader().decode(bitmap);
return result.getText();
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project java-learning by HouariZegai.
the class QRCodeReader method decodeQRCode.
private static String decodeQRCode(File qrCodeimage) {
BufferedImage bufferedImage = null;
try {
bufferedImage = ImageIO.read(qrCodeimage);
} catch (IOException ioe) {
ioe.printStackTrace();
}
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
try {
Result result = new MultiFormatReader().decode(bitmap);
return result.getText();
} catch (NotFoundException nfe) {
System.out.println("There is no QR code in the image!");
return null;
}
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project -- by 981011512.
the class QRCodeUtils method getContentFromQRCode.
public String getContentFromQRCode(String filePath) {
MultiFormatReader formatReader = new MultiFormatReader();
File file = new File(filePath);
BufferedImage image;
try {
image = ImageIO.read(file);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
HashMap hints = new HashMap();
// 指定字符编码为“utf-8”
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
Result result = formatReader.decode(binaryBitmap, hints);
return result.toString();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
Aggregations