

C using ZXing.Common using ZXing using ZXing.QrCode Step 2: Coding in your Form Load For Width or Height, you can change it to any value you want. LOG.severe("Could not generate a QR code. Step 1: Using Zxing Library using Zxing library from your reference. It also contains several applications for Android.

Return BASE64_PREFIX + new String(Base64.getEncoder().encode(outputStream.toByteArray())) At heart is it a pure Java library for decoding barcodes (the core/ and javase/ modules). ImageIO.write(bufferedImage, DEFAULT_IMAGE_FORMAT, outputStream) Public static String toBase64QrCode(final String input,įinal BufferedImage bufferedImage = toQrCode(input, width, height) īyteArrayOutputStream outputStream = new ByteArrayOutputStream() LOG.severe("Could not generate a QR code.") Return MatrixToImageWriter.toBufferedImage(bitMatrix) Hints.put(EncodeHintType.MARGIN, QR_CODE_WHITESPACE_MARGIN) įinal BitMatrix bitMatrix = barcodeWriter.encode(input, BarcodeFormat.QR_CODE, width, height, hints) Hints.put(EncodeHintType.CHARACTER_SET, UTF_8_CHARSET) Public static BufferedImage toQrCode(final String input,įinal QRCodeWriter barcodeWriter = new QRCodeWriter() įinal Map hints = new EnumMap(EncodeHintType.class) Private static final String UTF_8_CHARSET = "UTF-8" Private static final String DEFAULT_IMAGE_FORMAT = "png" Private static final int QR_CODE_WHITESPACE_MARGIN = 2 Private static final int DEFAULT_QR_CODE_HEIGHT = 200 Private static final int DEFAULT_QR_CODE_WIDTH = 200 Private static final String BASE64_PREFIX = "data:image/png base64," Private static final Logger LOG = Logger.getLogger(()) to use as src attribute of an img HTML tag) Now let’s create a service that takes an input string and generates a QR code containing this string. First of all, let’s add the following Maven dependencies:
