- Create the New Restful Application
- Dependency :
compile 'com.google.zxing:core:3.4.1'
compile 'com.google.zxing:javase:3.4.1'
ref link : https://mvnrepository.com/artifact/com.google.zxing/core/3.4.1
-
Create the service for the generationg the qr code :
-
Crete the controller to call the service to use it for creating the qr code
-
Make sure URLMapping is working fine
Complete ref : https://medium.com/nerd-for-tech/how-to-generate-qr-code-in-java-spring-boot-134adb81f10d
| Grails Version: 3.2.6
| Groovy Version: 2.4.7
| JVM Version: 1.8.0_181
git clone https://github.com/mindexpert7546/qr-code-generator.git
cd qr-code-generator
grails run-app
http://localhost:8080/qrgen
Now for final result : After url put / here the text will be converted into the qr
Supposed you enter :
http://localhost:8080/qrgen/mindexpert
In above url mindexpert will be converted into the qr.
-
Crete the object of QRCodeWriter (e.g - QRCodeWriter qrCodeWriter = new QRCodeWriter())
-
Use qrCodeWriter to generate the qr code and store to the BitMatrix in from of 2D array (e.g- BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height))
-
Crete the object of ByteArrayOutputStream to stor the qr code in form of byte (e.g- ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream())
-
Now the time to build complete qr code and store to the byte output Stream (e.g - MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOutputStream,config))
We have successfuly build the application to generate the qr code in form of the png format