有人知道如何使用Java程序生成二维码吗?我需要做一个应用程序来生成给安卓设备的细节二维码。谢谢!
发布于 2011-11-27 01:48:52
试试ZebraCrossing (ZXing),它看起来不错: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);发布于 2021-08-19 14:28:35
private Bitmap generateQRCodeFromText(String text) {
return QRCode.from(text)
.withSize(QR_CODE_SIZE, QR_CODE_SIZE)
.bitmap();
}或
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;
} 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;
}https://stackoverflow.com/questions/8280327
复制相似问题