Recognize Code_128 Barcode using Aspose.BarCode for Java

Hello

Recently, I have been using the software and there are many cases where the barcode is not recognized, can you help analyze the reason?barcode无法识别.zip (3.8 MB)

@bx609311029,
Can you please share the sample code that you are using to recognize these barcodes.

public class AsposeBarCode {
static {
License license = new License();
try {
InputStream resourceAsStream = AsposeBarCode.class.getClassLoader().getResourceAsStream(“license/Aspose.BarCode.lic”);
license.setLicense(resourceAsStream);
} catch (Exception e) {
log.error(“barcode error: {}”, e.getMessage());
}
}

private final static AsposeBarCode ASPOSE_BAR_CODE = new AsposeBarCode();

private AsposeBarCode() {

}

public static AsposeBarCode getInstance() {
    return ASPOSE_BAR_CODE;
}

/**
 * 读取barcode
 *
 * @param imgData
 * @return
 */
public Optional<String> readBarcode(byte[] imgData, BarcodeFilter filter) {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(imgData);
    BarCodeReader reader = new BarCodeReader(inputStream, DecodeType.CODE_128);
    final Optional<String> normal = readNormal(filter, reader);
    if (normal.isPresent()) {
        return normal;
    }

    return readHighQuality(filter, reader);
}


public Optional<String> readBarcode(String filename, BarcodeFilter filter) {
    BarCodeReader reader = new BarCodeReader(filename, DecodeType.CODE_128);
    return Optional.ofNullable(readNormal(filter, reader).orElse(readHighQuality(filter, reader).get()));

}

private Optional<String> readNormal(BarcodeFilter filter, BarCodeReader reader) {
    return read(filter, reader);
}

private Optional<String> read(BarcodeFilter filter, BarCodeReader reader) {
    BarCodeResult[] barCodeResults = reader.readBarCodes();
    for (BarCodeResult barCodeResult : barCodeResults) {
        final String codeText = barCodeResult.getCodeText();
        if (filter.accept(codeText)) {
            return Optional.of(codeText);
        }
    }

    return Optional.empty();
}

private Optional<String> readHighQuality(BarcodeFilter filter, BarCodeReader reader) {
    reader.setQualitySettings(QualitySettings.getHighQuality());
    return read(filter, reader);
}

}

@bx609311029,

I tested your scenario/case using the simplest lines of code (as following) with your provided images (barcodes) using Aspose.BarCode for Java v21.6 (please try it), it works fine and barcode is recognized and retrieved from your provided images:
e.g.
Sample code:

com.aspose.barcode.License license = new com.aspose.barcode.License();
                 license.setLicense("Aspose.BarCode.Java.lic");

                 String img = "E:\\test2\\barcode无法识别\\31c8d0b8b5f3c859068bee2b3ae313d9.png";
                 //String img = "E:\\test2\\barcode无法识别\\208_20210624131733208.jpeg";
                 //String img = "E:\\test2\\barcode无法识别\\313_20210604094008313.jpeg";
                 //String img = "E:\\test2\\barcode无法识别\\553_20210601100708553.jpeg";
                 //String img = "E:\\test2\\barcode无法识别\\649_20210604093755649.jpeg";
                 //String img = "E:\\test2\\barcode无法识别\\918_20210527104026918.jpeg";
                 //String img = "E:\\test2\\barcode无法识别\\934_20210527103540934.jpeg";
                 //String img = "E:\\test2\\barcode无法识别\\947_20210624131859947.jpeg";
                 //String img = "E:\\test2\\barcode无法识别\\wecom-temp-1a6013528a2d992f58c76ce729742c8b.jpg";
                 //String img = "E:\\test2\\barcode无法识别\\wecom-temp-d81a5c7078289698152c420cd62d7f7d.jpg";

                 // Initialize barcode reader
                 BarCodeReader reader = new BarCodeReader(img, DecodeType.CODE_128);
                 // Read all types of barcode
                 for (BarCodeResult result : reader.readBarCodes()) {
                     System.out.println("CodeText: " + result.getCodeText());
                     System.out.println("Symbology type: " + result.getCodeType());
                 } 

Let us know if you still find any issue with latest version of the API.