Hello,
i've a question why my code can't read attached file :
`
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.DecodeHintType;
import com.google.zxing.EncodeHintType;
import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.DecoderResult;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.multi.GenericMultipleBarcodeReader;
import com.google.zxing.qrcode.decoder.Decoder;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.qrcode.detector.Detector;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.Hashtable;
public class BarcodeImageDecoderTest {
public static void main(String[] args) throws Exception {
System.out.println(new BarcodeImageDecoderTest().readQRCode("./input/"));
}
private static Result[] readQRCode(String qrCodeImage) throws IOException, NotFoundException {
BufferedImage bfi = null;
File[] files = new File(qrCodeImage).listFiles();
int counttiffs = 0;
String filename = null;
TreeMap<String, Exception> errormap = new TreeMap<String, Exception>();
int onebarcode = 0;
int twobarcodes = 0;
int threebarcodes = 0;
BufferedImage cropedImage = null;
for (int i = 0; i < files.length; i++) {
if (files[i].isFile()) {
try (BufferedInputStream bfin = new BufferedInputStream(new FileInputStream(files[i]))) {
filename = files[i].getName();
bfi = ImageIO.read(bfin);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (
bfi != null) {
LuminanceSource ls = new BufferedImageLuminanceSource(bfi);
BinaryBitmap bmp = new BinaryBitmap(new HybridBinarizer(ls));
Reader reader = new MultiFormatReader();
GenericMultipleBarcodeReader greader = new GenericMultipleBarcodeReader(
reader);
Result[] result = null;
Hashtable<DecodeHintType, Object> decodeHints = new Hashtable<DecodeHintType, Object>();
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
decodeHints.put(DecodeHintType.POSSIBLE_FORMATS, Arrays.asList(BarcodeFormat.QR_CODE));
decodeHints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
try {
result = greader.decodeMultiple(bmp, decodeHints);
} catch (NotFoundException e) {
errormap.put(filename, e);
} catch (NullPointerException e) {
errormap.put(filename, e);
}
if (result != null) {
switch (result.length) {
case 1:
onebarcode++;
break;
case 3:
threebarcodes++;
break;
default:
twobarcodes++;
}
try (BufferedWriter bfwr = new BufferedWriter(
new FileWriter("test.txt", true))) {
bfwr.write(filename + ": number of barcodes found = "
+ result.length);
bfwr.newLine();
for (int j = 0; j < result.length; j++) {
bfwr.write(result[j].getText());
}
bfwr.newLine();
bfwr.write("---------------------------------------------------------");
bfwr.newLine();
counttiffs++;
} catch (IOException e) {
e.printStackTrace();
}
}
}
else {
System.out.println("No Buffered Image for "
+ files[i].getName());
}
}
}
return null;
}
}`
Please help
Thank You