import ch.codeblock.qrinvoice.MimeType;
import ch.codeblock.qrinvoice.QrInvoiceDocumentScanner;
import ch.codeblock.qrinvoice.model.QrInvoice;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
// ...
// either provide an input stream or a byte array
final InputStream imageInputStream = ...;
try {
// this option uses the default QR Code library and performs default scanning efforts
final QrCodeReaderOptions defaultOption = new QrCodeReaderOptions(ScanningEffortLevel.DEFAULT, QrCodeLibrary.DEFAULT);
// You may however increase scanning efforts by choosing level "HARDER", which may result in much slower operations but higher detection rate
// new QrCodeReaderOptions(ScanningEffortLevel.HARDER, QrCodeLibrary.DEFAULT);
// you may also choose to use BoofCV in addition to ZXing using any available ScanningEffortLevel combination
// new QrCodeReaderOptions(ScanningEffortLevel.DEFAULT, QrCodeLibrary.ZXING, QrCodeLibrary.BOOFCV);
// new QrCodeReaderOptions(ScanningEffortLevel.HARDER, QrCodeLibrary.ZXING, QrCodeLibrary.BOOFCV);
final Optional<QrInvoice> qrInvoiceOptional = QrInvoiceDocumentScanner.create(MimeType.PNG, defaultOption).scanDocumentUntilFirstSwissQrCode(imageInputStream);
if (qrInvoiceOptional.isPresent()) {
final QrInvoice qrInvoice = qrInvoiceOptional.get();
// access QR-Invoice structure
final BigDecimal amount = qrInvoice.getPaymentAmountInformation().getAmount();
// ...
} else {
// no Swiss QR Code found
}
} catch (IOException e) {
// io exception during read
}