搜集了二维码的生成、扫描功能代码,扫描功能 包括了 二维码、条码的扫描,具有 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);
// 通过像素数组生成bitmap,具体参考api
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
</encodehinttype,></encodehinttype,>
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.