Does anyone knows how to generate QR code using Java program? I need to make an application to generate QR code for given details to Android device. Thank you!
Asked
Active
Viewed 929 times
2
-
NO IT IS NOT JAVA. It's Java. – Martijn Courteaux Nov 26 '11 at 17:47
-
1No problem. But if I changed it myself, next time you would write it again like JAVA. Telling the people works better. :) – Martijn Courteaux Nov 26 '11 at 17:51
-
@MartijnCourteaux: Pet peeve? – Kevin Coppock Nov 26 '11 at 18:54
2 Answers
4
Try ZebraCrossing (ZXing), it looks good: http://code.google.com/p/zxing/
String contents = "Code";
BarCodeFormat barcodeFormat = BarCodeFormat.QR_CODE;
int width = 300;
int height = 300;
MultiFormatWriter barcodeWriter = new MultiFormatWriter();
BitMatrix matrix = barcodeWriter.encode(contents, barcodeFormat, width, height);
BufferedImage qrCodeImg = MatrixToImageWriter.toBufferedImage(matrix);

Martijn Courteaux
- 67,591
- 47
- 198
- 287
0
Check the below code using QRGen an api for java built on top ZXING
private Bitmap generateQRCodeFromText(String text) {
return QRCode.from(text)
.withSize(QR_CODE_SIZE, QR_CODE_SIZE)
.bitmap();
}
OR
private Bitmap generateQRCodeFromText(String text){
try {
QRCodeWriter writer = new QRCodeWriter();
BitMatrix bitMatrix = writer.encode(text, BarcodeFormat.QR_CODE, QR_CODE_SIZE, QR_CODE_SIZE);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
bmp.setPixel(x, y, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
}
}
return bmp;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
Or using zxing-android-embedded
private Bitmap generateQRCodeFromText(String text) {
try {
BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
Bitmap bmp= barcodeEncoder.encodeBitmap("content", BarcodeFormat.QR_CODE, 400, 400);
return bmp;
} catch(Exception e) {
e.printStackTrace();
}
return null;
}

MohamedHarmoush
- 1,033
- 11
- 17