二維碼的生成與掃描 源碼下載
作者:佚名
搜集了二維碼的生成、掃描功能代碼,掃描功能 包括了 二維碼、條碼的掃描,具有 360掃描的UI效果,作為二維碼的工具。
搜集了二維碼的生成、掃描功能代碼,掃描功能 包括了 二維碼、條碼的掃描,具有 360掃描的UI效果,作為二維碼的工具。
源碼簡介
源碼運行截圖
源碼片段
- /***
- *
- * @param string 生成二維碼的字符串
- * @param format 二維碼的格式
- * @return 返回二維碼圖片
- * @throws WriterException
- */
- public Bitmap qr_code(String string, BarcodeFormat format)
- throws WriterException {
- MultiFormatWriter writer = new MultiFormatWriter();
- Hashtable<encodehinttype, string=""> hst = new Hashtable<encodehinttype, string="">();
- hst.put(EncodeHintType.CHARACTER_SET, "UTF-8");
- BitMatrix matrix = writer.encode(string, format, 400, 400, hst);
- int width = matrix.getWidth();
- int height = matrix.getHeight();
- int[] pixels = new int[width * height];
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- if (matrix.get(x, y)) {
- pixels[y * width + x] = 0xff000000;
- }
- }
- }
- Bitmap bitmap = Bitmap.createBitmap(width, height,
- Bitmap.Config.ARGB_8888);
- // 通過像素數(shù)組生成bitmap,具體參考api
- bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
- return bitmap;
- }
- </encodehinttype,></encodehinttype,>
責任編輯:閆佳明
來源:
網(wǎng)絡整理