我需要在我的 android 应用程序中创建一个二维码,并且我需要一个库或源代码来让我在一个 Android 应用程序中创建一个二维码。
我需要的库必须:
- 不留水印(如
onbarcode
库) - 不使用网络服务 API 创建二维码(如 Google 的库 zxing)
- 不需要第 3 方安装程序(如 QR Droid)
我已经为 iPhone (Objective-C) 创建了这样的代码,但我需要快速修复 Android,直到我有时间制作自己的 QR 码生成器。这是我的第一个 android 项目,因此将不胜感激。
最佳答案
zxing 这是我创建二维码的代码
QRCodeWriter writer = new QRCodeWriter();
try {
BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, 512, 512);
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);
}
}
((ImageView) findViewById(R.id.img_result_qr)).setImageBitmap(bmp);
} catch (WriterException e) {
e.printStackTrace();
}
关于java - 如何为 Android 应用程序生成二维码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8800919/