生成二维码工具类
来源:互联网 发布:克什米尔与中国知乎 编辑:程序博客网 时间:2024/05/16 15:17
导入:
compile 'com.google.zxing:core:3.3.0'
工具类:
public class QRUtil {// 使用样例// ImageView mQRCode = (ImageView) mView.findViewById(R.id.qrcode);// Bitmap bitmap = Utils.createQRImage(context, mQRCode, info);// if (bitmap != null && !bitmap.isRecycled()){// mQRCode.setImageBitmap(bitmap);// } public static Bitmap createQRImage(Context context, View view, String id) { try { if (id == null || id.isEmpty()) { return null; } int width = 520; int height = 520; Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); BitMatrix bitMatrix = new QRCodeWriter().encode(id, BarcodeFormat.QR_CODE, width, height, hints); bitMatrix = deleteWhite(bitMatrix); int[] rec = bitMatrix.getEnclosingRectangle(); width = rec[2] + 1; height = rec[3] + 1; int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (bitMatrix.get(x, y)) { pixels[y * width + x] = 0xff000000; } else { pixels[y * width + x] = 0xffffffff; } } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; } catch (WriterException e) { e.printStackTrace(); } return null; } public static BitMatrix deleteWhite(BitMatrix matrix) { int[] rec = matrix.getEnclosingRectangle(); int resWidth = rec[2] + 1; int resHeight = rec[3] + 1; BitMatrix resMatrix = new BitMatrix(resWidth, resHeight); resMatrix.clear(); for (int i = 0; i < resWidth; i++) { for (int j = 0; j < resHeight; j++) { if (matrix.get(i + rec[0], j + rec[1])) { resMatrix.set(i, j); } } } return resMatrix; }}
阅读全文
0 0
- 二维码生成工具类
- 生成二维码工具类
- 二维码生成工具类
- ZXing二维码生成工具类
- java工具类------生成二维码
- java生成二维码工具类
- Qrcode生成二维码工具类
- java二维码工具类:生成二维码和解析二维码
- java 二维码工具类(二维码生成 解析)
- 【工具类】-条码生成类(一维码,二维码)
- 利用ZXing生成二维码的工具类
- 利用ZXing生成二维码的工具类
- 二维码图片生成和解析工具类
- java zxing 生成二维码工具类
- 利用ZXing生成二维码的工具类
- Android生成二维码的工具类
- 【开源框架】二维码生成工具类
- 二维码图片生成的工具类
- Java使用Apache FtpServer实现嵌入式FTP服务器
- windows C++ 通过UDP广播获取网络中所有设备ip地址
- java 深入了解DTO及如何使用DTO
- Luogu P1600 [NOIp提高组2016]天天爱跑步
- 绘图软件有哪些免费使用操作
- 生成二维码工具类
- 1041. 考试座位号(15)
- 笔试题--自动生成目录
- VC--获取本机 局域网IP 和外网IP
- 未来人工智能在手机的应用
- Android弹出软键盘布局是否上移问题
- php字符串截取,支持中文和其他编码
- Tensorflow-释放GPU内存
- HTTP与HTTPS的区别