Generate QR code of any URL in Java

import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class NewClass1 {
private static final String qrOutput = "C://Users//Administrator//Desktop//QR Code.JPEG";
private static void generateQRCode(String text, int width, int height, String filePath)
throws Exception {
QRCodeWriter qrCodeWriterObj = new QRCodeWriter();
BitMatrix bitMatrixObj = qrCodeWriterObj.encode(text, BarcodeFormat.QR_CODE, width, height);
Path pathObj = FileSystems.getDefault().getPath(filePath);
MatrixToImageWriter.writeToPath(bitMatrixObj, "JPEG", pathObj);
}
public static void main(String[] args) {
try {
generateQRCode("Thank you for using CodeSpeedy", 1250, 1250, qrOutput);
} 
catch (Exception e){
System.out.println("Could not generate QR Code" + e);
}
}
}

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top