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;
}
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();
}
Aggregations