-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbarcodeScanner.java
34 lines (28 loc) · 1.25 KB
/
barcodeScanner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.QRCodeReader;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class BarcodeScanner {
public static String decodeBarcode(File barcodeImageFile) throws IOException, NotFoundException {
BufferedImage bufferedImage = ImageIO.read(barcodeImageFile);
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Reader reader = new MultiFormatReader();
Result result = reader.decode(bitmap);
return result.getText();
}
public static void main(String[] args) {
try {
File barcodeFile = new File("path_to_barcode_image.jpg");
String barcodeText = decodeBarcode(barcodeFile);
System.out.println("Decoded text from barcode: " + barcodeText);
// Proceed to search for student information using the decoded text (NIC)
} catch (IOException | NotFoundException e) {
e.printStackTrace();
}
}
}