As in earlier post we had learn what is QR code and how can we generate QR code in java and servlet.
Now here I will show you how can we read QR Code in java.
Here again i had use same jar file as we had previous. ZXing- Zibra Corossing
Here is code to read/decode QR Code.
file: QRReader.java
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();
}
}
}
I hope, now you are clear with QR Code generation and decoding using Java.
Hello, Dhaval Shah
ReplyDeleteThank you so much for your tutorial, nice sharing. It's refreshing to find someone who gives me actual, functioning guide and example of developer java qr code decoder. I apply it in my project with success.
Thank you again for your kind sharing.