-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRCodeGenerator.java
More file actions
29 lines (25 loc) · 1.07 KB
/
Copy pathQRCodeGenerator.java
File metadata and controls
29 lines (25 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
public class QRCodeGenerator {
public static void generateQRCode(String text, String filePath) throws WriterException, IOException {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, 300, 300);
Path path = FileSystems.getDefault().getPath(filePath);
MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);
}
public static void main(String[] args) {
try {
String tableLink = "http://localhost:8080/table/1";
generateQRCode(tableLink, "assets/qrcodes/table1.png");
System.out.println("QR Code generated for Table 1");
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
}