Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please go through this <a href="http://javapapers.com/core-java/java-qr-code/" rel="noreferrer">link</a> for complete Tutorial. The author of this code is Joe. <strong>I have not developed this code</strong>, so I am just doing Copy paste to make sure this is available in case link is broken.</p> <p>The author is using ZXing(Zebra Crossing Library) you can download it from <a href="https://code.google.com/p/zxing/" rel="noreferrer">here</a>, for this tutorial.</p> <p><strong>QR Code Write and Read Program in Java:</strong></p> <pre><code>package com.javapapers.java; import java.io.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.EncodeHintType; import com.google.zxing.MultiFormatReader; import com.google.zxing.MultiFormatWriter; import com.google.zxing.NotFoundException; import com.google.zxing.Result; import com.google.zxing.WriterException; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; public class QRCode { public static void main(String[] args) throws WriterException, IOException, NotFoundException { String qrCodeData = "Hello World!"; String filePath = "QRCode.png"; String charset = "UTF-8"; // or "ISO-8859-1" Map&lt;EncodeHintType, ErrorCorrectionLevel&gt; hintMap = new HashMap&lt;EncodeHintType, ErrorCorrectionLevel&gt;(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); createQRCode(qrCodeData, filePath, charset, hintMap, 200, 200); System.out.println("QR Code image created successfully!"); System.out.println("Data read from QR Code: " + readQRCode(filePath, charset, hintMap)); } public static void createQRCode(String qrCodeData, String filePath, String charset, Map hintMap, int qrCodeheight, int qrCodewidth) throws WriterException, IOException { BitMatrix matrix = new MultiFormatWriter().encode( new String(qrCodeData.getBytes(charset), charset), BarcodeFormat.QR_CODE, qrCodewidth, qrCodeheight, hintMap); MatrixToImageWriter.writeToFile(matrix, filePath.substring(filePath .lastIndexOf('.') + 1), new File(filePath)); } public static String readQRCode(String filePath, String charset, Map hintMap) throws FileNotFoundException, IOException, NotFoundException { BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer( new BufferedImageLuminanceSource( ImageIO.read(new FileInputStream(filePath))))); Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap, hintMap); return qrCodeResult.getText(); } } </code></pre> <p><strong>Maven dependency for the ZXing QR Code library:</strong></p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;com.google.zxing&lt;/groupId&gt; &lt;artifactId&gt;core&lt;/artifactId&gt; &lt;version&gt;2.2&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;com.google.zxing&lt;/groupId&gt; &lt;artifactId&gt;javase&lt;/artifactId&gt; &lt;version&gt;2.2&lt;/version&gt; &lt;/dependency&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload