用于二维码生成的Android Zxing库
我想在我的应用程序中生成一个文本的二维码,但我不知道如何实现。如何实现此功能?有任何帮助吗;用于二维码生成的Android Zxing库,android,zxing,Android,Zxing,我想在我的应用程序中生成一个文本的二维码,但我不知道如何实现。如何实现此功能?有任何帮助吗; below code can help you to generate qr code Intent intent = new Intent(); intent.setAction(Intents.Encode.ACTION); intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString()); intent.putEx
below code can help you to generate qr code
Intent intent = new Intent();
intent.setAction(Intents.Encode.ACTION);
intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString());
intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT);
intent.putExtra(Intents.Encode.DATA, codeString);
QRCodeEncoder qrcode = new QRCodeEncoder(YourActivity.this, intent,250);
try {
Bitmap bitmap = qrcode.encodeAsBitmap();
imgBarcode = (ImageView) findViewById(R.id.imgbarcode);
imgBarcode.setImageBitmap(bitmap);
} catch (WriterException e) {
e.printStackTrace();
}
尝试
{
EnumMap hint=新的EnumMap(EncodeHintType.class);
提示.put(EncodeHintType.CHARACTER_集,“UTF-8”);
BitMatrix BitMatrix=writer.encode(内容、条形码格式、QR_码、尺寸、尺寸、提示);
int-width=bitMatrix.getWidth();
int height=bitMatrix.getHeight();
int[]像素=新int[宽度*高度];
对于(int y=0;yQRCodeWriter writer=新的QRCodeWriter();
尝试
{
EnumMap hint=新的EnumMap(EncodeHintType.class);
提示.put(EncodeHintType.CHARACTER_集,“UTF-8”);
BitMatrix BitMatrix=writer.encode(内容、条形码格式、QR_码、尺寸、尺寸、提示);
int-width=bitMatrix.getWidth();
int height=bitMatrix.getHeight();
int[]像素=新int[宽度*高度];
对于(int y=0;y
您需要将最新版本的ZXing中的core.jar
文件添加到您的项目中。您还需要向项目中添加另外两个类
下面是一个关于如何操作的示例。您需要将ZXing最新版本中的
core.jar
文件添加到您的项目中。您还需要向项目中添加两个类
这里有一个关于如何做的例子。阅读文档。如果可能,用意图的方式做。阅读文档。如果可能,用意图的方式做。我对BarcodeFornat.QR_CODE.toString()有一个问题,它说java.lang.NoClassDefFoundError:com.google.zxing.BarcodeFormat,你能帮我吗?你使用的是什么版本的zxing库?写吧“二维码"相反,您不想从core/@Marckaraujo导入类,如
BarcodeFormat
,我可以共享由此代码生成的Qrcode吗?如果是,我是否需要将生成的Qrcode保存在设备SD卡中,然后share@ErumHannan,是的,您可以共享此qrcode,您无需保存qrcode即可共享,您只需保存你想在拿到qrcode后再分享它。我发现BarcodeFornat.QR_CODE.toString()有问题,上面写着java.lang.NoClassDefFoundError:com.google.zxing.BarcodeFormat,你能帮我吗?你使用的是什么版本的zxing库?只要写“QR_CODE”相反,您不想从core/@Marckaraujo导入类,如BarcodeFormat
,我可以共享由此代码生成的Qrcode吗?如果是,我是否需要将生成的Qrcode保存在设备SD卡中,然后share@ErumHannan,是的,您可以共享此qrcode,您无需保存qrcode即可共享,您只需保存你想分享QR码,但不是在你拿到它之后。
QRCodeWriter writer = new QRCodeWriter();
try
{
EnumMap<EncodeHintType, Object> hint = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hint.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, dimention, dimention, hint);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
int[] pixels = new int[width * height];
for (int y = 0; y < height; y++)
{
int offset = y * width;
for (int x = 0; x < width; x++)
{
// pixels[offset + x] = bitMatrix.get(x, y) ? 0xFF000000
// : 0xFFFFFFFF;
pixels[offset + x] = bitMatrix.get(x, y) ? colorBack : colorFront;
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;