Hi i have tried to read a barcode from image using below code but i am unable to read the file as it contains multiple barcodes. Is there any work around for this?
I think you should learn fundamentals-of-algorithms and Java first then just TRY_HARDER and use GenericMultipleBarcodeReader :)
public class MbcPoc {
public static void main(String... args) throws NotFoundException, IOException {
List list = decodeImageWithMBC("fREyt.png");
list.forEach(BarcodeInfo::println);
}
private static List decodeImageWithMBC(String imgPath) throws NotFoundException, IOException {
BufferedImage img = ImageIO.read(new File(imgPath));
BinaryBitmap bb = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(img)));
MultipleBarcodeReader mbReader = new GenericMultipleBarcodeReader(new MultiFormatReader());
Hashtable hints = new Hashtable<>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
List list = new ArrayList<>();
for (Result result : mbReader.decodeMultiple(bb, hints)) {
list.add(new BarcodeInfo(result.getText(), result.getBarcodeFormat().name()));
}
return list;
}
public static class BarcodeInfo {
private final String text;
private final String format;
BarcodeInfo(String text, String format) {
this.text = text;
this.format = format;
}
public static void println(BarcodeInfo bci) {
System.out.println(bci.text + "/" + bci.format);
}
}
}