use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project SeleniumTestNGParallel by anhtester.
the class TestQRCode method QRCode.
@Test
public void QRCode() throws NotFoundException, IOException {
driver.get("http://qrcode.meetheed.com/qrcode_examples.php");
driver.manage().window().maximize();
String qrCodeURL = driver.findElement(By.xpath("//img[@src='images/qr_code_con.png']")).getAttribute("src");
// Create an object of URL Class
URL url = new URL(qrCodeURL);
// Pass the URL class object to store the file as image
BufferedImage bufferedimage = ImageIO.read(url);
// Process the image
LuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedimage);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
// To Capture details of QR code
Result result = new MultiFormatReader().decode(binaryBitmap);
System.out.println(result.getText());
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project bh3login by Yarukon.
the class Main method doScan.
public static void doScan() {
try {
// 登录结果, 解析自个写就行
JsonObject result = (JsonObject) JsonParser.parseString(FileUtils.readFileToString(new File("E:/BH3BiliLogin/result.json"), "UTF-8"));
QRScanner scanner = new QRScanner(result.get("uid").getAsString(), result.get("access_key").getAsString());
// 全屏截图找二维码 所以确保没别的二维码在桌面上
Robot robot = new Robot();
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
System.out.println("屏幕大小: " + d);
MultiFormatReader multiFormatReader = new MultiFormatReader();
LuminanceSource source = new BufferedImageLuminanceSource(robot.createScreenCapture(new Rectangle(d)));
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map hints = new HashMap();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
Result scanResult = multiFormatReader.decode(binaryBitmap, hints);
// 解析URL并登入
HashMap<String, String> shit = Utils.stripUrl(URLDecoder.decode(scanResult.getText(), "UTF-8"));
scanner.bizKey = shit.get("biz_key");
scanner.ticket = shit.get("ticket");
scanner.appID = shit.get("app_id");
scanner.doQRLogin();
} catch (Exception ex) {
// 错误抛出
System.out.println("如果错误为com.google.zxing.NotFoundException代表未找到二维码");
ex.printStackTrace();
}
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project openpnp by openpnp.
the class CameraLatencyTest method paint.
@Override
public void paint(Graphics g) {
BufferedImage image = this.image;
// TODO only send the QR code 4x a second or so instead of on every frame to reduce
// load
long time = System.currentTimeMillis();
try {
long t = System.currentTimeMillis();
Map hintMap = new HashMap();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap, hintMap);
latency = time - Long.parseLong(qrCodeResult.getText());
System.arraycopy(latencies, 1, latencies, 0, latencies.length - 1);
latencies[latencies.length - 1] = latency;
averageLatency = 0;
for (int i = 0; i < latencies.length; i++) {
averageLatency += latencies[i];
}
averageLatency /= latencies.length;
flashCount = 6;
} catch (Exception e) {
}
g.setColor(Color.black);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(Color.white);
g.drawImage(image, 0, 0, null);
g.drawString("Time: " + (System.currentTimeMillis() - t), 10, 40);
g.drawString("FPS: " + fps, 10, 60);
if (flashCount-- > 0) {
g.setColor(Color.green);
}
g.drawString("Latency: " + latency, 10, 80);
g.drawString(String.format("Average Latency: %.2f", averageLatency), 10, 100);
try {
Map hintMap = new HashMap();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix matrix = new MultiFormatWriter().encode("" + System.currentTimeMillis(), BarcodeFormat.QR_CODE, 64, 64, hintMap);
BufferedImage qrCode = MatrixToImageWriter.toBufferedImage(matrix);
g.drawImage(qrCode, 20, 120, null);
} catch (Exception e) {
}
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project lilishop by lilishop.
the class QrCodeKit method decode.
/**
* @param srcImgFilePath 要解码的图片地址
* @return {Result}
*/
public static Result decode(String srcImgFilePath) {
Result result = null;
BufferedImage image;
try {
File srcFile = new File(srcImgFilePath);
image = ImageIO.read(srcFile);
if (null != image) {
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
result = new MultiFormatReader().decode(bitmap, hints);
} else {
throw new IllegalArgumentException("Could not decode image.");
}
} catch (Exception e) {
log.error("图片解码错误", e);
}
return result;
}
use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project spring-commons by damianwajser.
the class DefaultFormatter method read.
public String read(byte[] qr) throws NotFoundException, IOException {
InputStream qrBytes = new ByteArrayInputStream(qr);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(qrBytes))));
Result result = new MultiFormatReader().decode(binaryBitmap);
return result.getText();
}
Aggregations