Skip to content

Instantly share code, notes, and snippets.

@thieunguyenhung
Last active August 6, 2019 08:36
Show Gist options
  • Save thieunguyenhung/da8ca16adc281f6b7d0ee6be89ab2e35 to your computer and use it in GitHub Desktop.
Save thieunguyenhung/da8ca16adc281f6b7d0ee6be89ab2e35 to your computer and use it in GitHub Desktop.
Example how to create BitMatrix of QR code with Google ZXing
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.util.HashMap;
import java.util.Map;
//.......
private BitMatrix createBitMatrix(String qrCodeText, int size) throws WriterException {
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.MARGIN, DEFAULT_MARGIN);
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
return new QRCodeWriter().encode(qrCodeText, BarcodeFormat.QR_CODE, size, size, hints);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment