QR code test

This commit is contained in:
Jörg Prante 2025-01-15 11:55:14 +01:00
parent 0564b2e934
commit 2dedbc154f

View file

@ -17,14 +17,11 @@ import java.nio.file.Paths;
public class QRCodeTest { public class QRCodeTest {
/**
* The hard way by using Okapi Barcode.
* @throws IOException
*/
@Test @Test
public void createQRCode() throws IOException { public void createQRCode() throws IOException {
//String content = "IFLA-15: Kostenlimit überschritten, erneute Bestellung, wenn Kosten akzeptiert werden"; //String content = "IFLA-15: Kostenlimit überschritten, erneute Bestellung, wenn Kosten akzeptiert werden";
String content = "IFLA-16:"; //String content = "IFLA-16:";
int x = 0; int x = 0;
int y = 0; int y = 0;
int width = 128; int width = 128;
@ -34,7 +31,7 @@ public class QRCodeTest {
code.setQuietZoneHorizontal(1); code.setQuietZoneHorizontal(1);
code.setQuietZoneVertical(1); code.setQuietZoneVertical(1);
code.setEccMode(QrCode.EccMode.L); code.setEccMode(QrCode.EccMode.L);
code.setContent(content); //code.setContent(content);
double scalingFactor = 5.0d; double scalingFactor = 5.0d;
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);
BarcodeGraphicsRenderer renderer = createRenderer(bufferedImage, x, y, scalingFactor, scalingFactor); BarcodeGraphicsRenderer renderer = createRenderer(bufferedImage, x, y, scalingFactor, scalingFactor);
@ -56,14 +53,12 @@ public class QRCodeTest {
/** /**
* Easy way by using zxing. * Easy way by using zxing.
* @throws IOException * @throws IOException
* @throws NotFoundException
* @throws WriterException
*/ */
@Test @Test
public void testQrCode() throws IOException, NotFoundException, WriterException { public void testQrCode() throws IOException {
QRCodeWriter qrCodeWriter = new QRCodeWriter(); QRCodeWriter qrCodeWriter = new QRCodeWriter();
try (OutputStream outputStream = Files.newOutputStream(Paths.get("build/ifla-20.png"))) { try (OutputStream outputStream = Files.newOutputStream(Paths.get("build/de-361-ifla-20.png"))) {
qrCodeWriter.write("IFLA-20: Art der gewünschten Lieferung nicht möglich", qrCodeWriter.write("DE-361: IFLA-20: Art der gewünschten Lieferung nicht möglich",
outputStream, "png", 200, 200); outputStream, "png", 200, 200);
} }
} }