Search in sources :

Example 16 with MatrixToImageConfig

use of com.google.zxing.client.j2se.MatrixToImageConfig in project sparrow by sparrowwallet.

the class ReceiveController method getQrCode.

private Image getQrCode(String address) {
    try {
        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        BitMatrix qrMatrix = qrCodeWriter.encode(address, BarcodeFormat.QR_CODE, 130, 130, Map.of(EncodeHintType.MARGIN, 2));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        MatrixToImageWriter.writeToStream(qrMatrix, "PNG", baos, new MatrixToImageConfig());
        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        return new Image(bais);
    } catch (Exception e) {
        log.error("Error generating QR", e);
    }
    return null;
}
Also used : QRCodeWriter(com.google.zxing.qrcode.QRCodeWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) BitMatrix(com.google.zxing.common.BitMatrix) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MatrixToImageConfig(com.google.zxing.client.j2se.MatrixToImageConfig) Image(javafx.scene.image.Image)

Example 17 with MatrixToImageConfig

use of com.google.zxing.client.j2se.MatrixToImageConfig in project spring-commons by damianwajser.

the class DefaultFormatter method write.

public byte[] write(String text, int width, int height) throws WriterException, IOException {
    LOGGER.info("Will generate image code=[{}], width=[{}], height=[{}]", text, width, height);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BitMatrix matrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height);
    MatrixToImageWriter.writeToStream(matrix, MediaType.IMAGE_PNG.getSubtype(), baos, new MatrixToImageConfig());
    return baos.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BitMatrix(com.google.zxing.common.BitMatrix) MatrixToImageConfig(com.google.zxing.client.j2se.MatrixToImageConfig)

Aggregations

MatrixToImageConfig (com.google.zxing.client.j2se.MatrixToImageConfig)17 BitMatrix (com.google.zxing.common.BitMatrix)13 BufferedImage (java.awt.image.BufferedImage)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 WriterException (com.google.zxing.WriterException)5 QRCodeWriter (com.google.zxing.qrcode.QRCodeWriter)5 MultiFormatWriter (com.google.zxing.MultiFormatWriter)4 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 EncodeHintType (com.google.zxing.EncodeHintType)3 Color (java.awt.Color)3 Font (java.awt.Font)3 Graphics2D (java.awt.Graphics2D)3 File (java.io.File)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Image (javafx.scene.image.Image)2 BarcodeFormat (com.google.zxing.BarcodeFormat)1 NotFoundException (com.google.zxing.NotFoundException)1 SymbolShapeHint (com.google.zxing.datamatrix.encoder.SymbolShapeHint)1 ImportException (com.sparrowwallet.sparrow.io.ImportException)1