Read QRCode in JAVA

Hello Friends,

As in earlier post we had learn what is QR code and how can we generate QR code in java and servlet.

Now here today we will learn how can we read QR Code in java.

Here again i had use same jar file as we had previuos. ZXing- Zibra Corossing

Here is code to read QR Code.


import java.io.FileInputStream;
import javax.imageio.ImageIO;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

public class QRReader {

public static void main(String args[]){

Result result = null;
BinaryBitmap binaryBitmap;

try{

binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(new FileInputStream("D:/Generated_QR.PNG")))));
result = new MultiFormatReader().decode(binaryBitmap);
System.out.println("QR Code : "+result.getText());

}catch(Exception ex){
ex.printStackTrace();
}
}
}

 

Hope you like it. Cheers… 🙂