add code39 and qrcode writer based on zxing

This commit is contained in:
Jörg Prante 2023-12-08 08:46:23 +01:00
parent 45b783c90a
commit 1cfc5b2989
4 changed files with 44 additions and 21 deletions

View file

@ -1,5 +1,5 @@
group = org.xbib.graphics
name = graphics
version = 5.3.0
version = 5.3.1
org.gradle.warning.mode = ALL

View file

@ -47,7 +47,7 @@ module org.xbib.graphics.barcode {
exports org.xbib.graphics.barcode.util;
exports org.xbib.graphics.barcode.render;
requires transitive java.desktop;
requires org.xbib.graphics.zxing;
requires transitive org.xbib.graphics.zxing;
provides SymbolProvider with
AustraliaPost.Provider,
AztecCode.Provider,

View file

@ -2,7 +2,6 @@ package org.xbib.graphics.barcode.render;
import org.xbib.graphics.zxing.BarcodeFormat;
import org.xbib.graphics.zxing.MultiFormatWriter;
import org.xbib.graphics.zxing.NotFoundException;
import org.xbib.graphics.zxing.WriterException;
import org.xbib.graphics.zxing.common.BitMatrix;
@ -17,21 +16,33 @@ public class Code39Writer {
}
public void write(String content, Path path, String format, int width, int height)
throws WriterException, IOException, NotFoundException {
throws IOException {
try {
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height);
MatrixToImageWriter.writeToPath(matrix, format, path);
} catch (WriterException e) {
throw new IOException(e);
}
}
public void write(String content, OutputStream outputStream, String format, int width, int height)
throws WriterException, IOException, NotFoundException {
throws IOException {
try {
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height);
MatrixToImageWriter.writeToStream(matrix, format, outputStream);
} catch (WriterException e) {
throw new IOException(e);
}
}
public BufferedImage write(String content, int width, int height)
throws WriterException, IOException, NotFoundException {
throws IOException {
try {
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_39, width, height);
return MatrixToImageWriter.toBufferedImage(matrix);
} catch (WriterException e) {
throw new IOException(e);
}
}
}

View file

@ -18,20 +18,32 @@ public class QRCodeWriter {
}
public void write(String content, Path path, String format, int width, int height)
throws WriterException, IOException, NotFoundException {
throws IOException {
try {
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height);
MatrixToImageWriter.writeToPath(matrix, format, path);
} catch (WriterException e) {
throw new IOException(e);
}
}
public void write(String content, OutputStream outputStream, String format, int width, int height)
throws WriterException, IOException, NotFoundException {
throws IOException {
try {
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height);
MatrixToImageWriter.writeToStream(matrix, format, outputStream);
} catch (WriterException e) {
throw new IOException(e);
}
}
public BufferedImage write(String content, int width, int height)
throws WriterException, IOException, NotFoundException {
throws IOException {
try {
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height);
return MatrixToImageWriter.toBufferedImage(matrix);
} catch (WriterException e) {
throw new IOException(e);
}
}
}