Java源码示例:net.glxn.qrgen.QRCode

示例1
@FXML
protected void showQRCode(MouseEvent event) {
    // Serialize to PNG and back into an image. Pretty lame but it's the shortest code to write and I'm feeling
    // lazy tonight.
    final byte[] imageBytes = QRCode
            .from(uri())
            .withSize(320, 240)
            .to(ImageType.PNG)
            .stream()
            .toByteArray();
    Image qrImage = new Image(new ByteArrayInputStream(imageBytes));
    ImageView view = new ImageView(qrImage);
    view.setEffect(new DropShadow());
    // Embed the image in a pane to ensure the drop-shadow interacts with the fade nicely, otherwise it looks weird.
    // Then fix the width/height to stop it expanding to fill the parent, which would result in the image being
    // non-centered on the screen. Finally fade/blur it in.
    Pane pane = new Pane(view);
    pane.setMaxSize(qrImage.getWidth(), qrImage.getHeight());
    final Main.OverlayUI<ClickableBitcoinAddress> overlay = Main.instance.overlayUI(pane, this);
    view.setOnMouseClicked(event1 -> overlay.done());
}
 
示例2
@FXML
protected void showQRCode(MouseEvent event) {
    // Serialize to PNG and back into an image. Pretty lame but it's the shortest code to write and I'm feeling
    // lazy tonight.
    final byte[] imageBytes = QRCode
            .from(uri())
            .withSize(320, 240)
            .to(ImageType.PNG)
            .stream()
            .toByteArray();
    Image qrImage = new Image(new ByteArrayInputStream(imageBytes));
    ImageView view = new ImageView(qrImage);
    view.setEffect(new DropShadow());
    // Embed the image in a pane to ensure the drop-shadow interacts with the fade nicely, otherwise it looks weird.
    // Then fix the width/height to stop it expanding to fill the parent, which would result in the image being
    // non-centered on the screen. Finally fade/blur it in.
    Pane pane = new Pane(view);
    pane.setMaxSize(qrImage.getWidth(), qrImage.getHeight());
    final Main.OverlayUI<ClickableBitcoinAddress> overlay = Main.instance.overlayUI(pane, this);
    view.setOnMouseClicked(event1 -> overlay.done());
}
 
示例3
@FXML
protected void showQRCode(MouseEvent event) {
    // Serialize to PNG and back into an image. Pretty lame but it's the shortest code to write and I'm feeling
    // lazy tonight.
    final byte[] imageBytes = QRCode
            .from(uri())
            .withSize(320, 240)
            .to(ImageType.PNG)
            .stream()
            .toByteArray();
    Image qrImage = new Image(new ByteArrayInputStream(imageBytes));
    ImageView view = new ImageView(qrImage);
    view.setEffect(new DropShadow());
    // Embed the image in a pane to ensure the drop-shadow interacts with the fade nicely, otherwise it looks weird.
    // Then fix the width/height to stop it expanding to fill the parent, which would result in the image being
    // non-centered on the screen. Finally fade/blur it in.
    Pane pane = new Pane(view);
    pane.setMaxSize(qrImage.getWidth(), qrImage.getHeight());
    final Main.OverlayUI<ClickableBitcoinAddress> overlay = Main.instance.overlayUI(pane, this);
    view.setOnMouseClicked(event1 -> overlay.done());
}
 
示例4
protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  TwoFactorServlet.preventCaching(response);
  String username = request.getParameter("username");
  String secret = request.getParameter("secret");

  String pic = makeTotpUrl(ISSUER, username, secret);
  ByteArrayOutputStream qrImageOutput = QRCode.from(pic).to(ImageType.PNG)
      .stream();
  response.setContentType("image/png");
  response.setContentLength(qrImageOutput.size());
  OutputStream outStream = response.getOutputStream();
  outStream.write(qrImageOutput.toByteArray());
  outStream.flush();
  outStream.close();
}
 
示例5
public QRCodeWindow(String bitcoinURI) {
    this.bitcoinURI = bitcoinURI;
    final byte[] imageBytes = QRCode
            .from(bitcoinURI)
            .withSize(250, 250)
            .to(ImageType.PNG)
            .stream()
            .toByteArray();
    Image qrImage = new Image(new ByteArrayInputStream(imageBytes));
    qrCodeImageView = new ImageView(qrImage);

    type = Type.Information;
    width = 468;
    headLine(Res.get("qRCodeWindow.headline"));
    message(Res.get("qRCodeWindow.msg"));
}
 
示例6
public void update () {

        PaymentRequest paymentRequest = Main.thunderContext.receivePayment(getAmount());

        try {

            byte[] payload = paymentRequest.getPayload();

            FieldAddress.setText(Tools.bytesToHex(payload));
            FieldHash.setText(Tools.bytesToHex(paymentRequest.paymentSecret.hash));

            System.out.println(Tools.bytesToHex(payload));

            final byte[] imageBytes = QRCode
                    .from(Tools.bytesToHex(payload))
                    .withSize(250, 250)
                    .to(ImageType.PNG)
                    .stream()
                    .toByteArray();

            Image qrImage = new Image(new ByteArrayInputStream(imageBytes));
            ImageQR.setImage(qrImage);
            ImageQR.setEffect(new DropShadow());

            StringSelection stringSelection = new StringSelection(Tools.bytesToHex(payload));
            Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
            clpbrd.setContents(stringSelection, null);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
 
示例7
public void update () {

        System.out.println(Tools.bytesToHex(Main.node.pubKeyServer.getPubKey()));

        if (secret == null) {
            secret = new PaymentSecret(Tools.getRandomByte(20));
            Main.dbHandler.addPaymentSecret(secret);
            System.out.println("HASH: "+Tools.bytesToHex(secret.hash));
        }

        try {

            byte[] payload = getPayload();

            FieldAddress.setText(Tools.bytesToHex(payload));
            FieldHash.setText(Tools.bytesToHex(secret.hash));

            System.out.println(Tools.bytesToHex(payload));

            final byte[] imageBytes = QRCode
                    .from(Tools.bytesToHex(payload))
                    .withSize(250, 250)
                    .to(ImageType.PNG)
                    .stream()
                    .toByteArray();

            Image qrImage = new Image(new ByteArrayInputStream(imageBytes));
            ImageQR.setImage(qrImage);
            ImageQR.setEffect(new DropShadow());

            StringSelection stringSelection = new StringSelection(Tools.bytesToHex(payload));
            Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
            clpbrd.setContents(stringSelection, null);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
 
示例8
private void updateQRCode() {
    if (addressTextField.getAddress() != null && !addressTextField.getAddress().isEmpty()) {
        final byte[] imageBytes = QRCode
                .from(getBitcoinURI())
                .withSize(150, 150) // code has 41 elements 8 px is border with 150 we get 3x scale and min. border
                .to(ImageType.PNG)
                .stream()
                .toByteArray();
        Image qrImage = new Image(new ByteArrayInputStream(imageBytes));
        qrCodeImageView.setImage(qrImage);
    }
}
 
示例9
/**
 * 生成二维码
 * @param content 内容
 * @param charset 字符编码
 * @param width 宽
 * @param height 高
 * @param target 生成后写入路径
 * @throws FileNotFoundException
 * @throws IOException
 */
private static void generateCode(String content,String charset,int width,int height,File target) throws FileNotFoundException,IOException {
	
	ByteArrayOutputStream out = QRCode.from(content).withCharset(charset).withSize(width, height).to(ImageType.PNG).stream();

	OutputStream outStream = new FileOutputStream(target);

	outStream.write(out.toByteArray());

	outStream.flush();
	outStream.close();
	
}