Zxing关于Android端生产二维码

来源:互联网 发布:大数据时代人工智能 编辑:程序博客网 时间:2024/05/04 08:05
 public static Bitmap createQRCode(String text, int size) {        try {            Hashtable<EncodeHintType, String> hints = new Hashtable<>();            hints.put(EncodeHintType.CHARACTER_SET, "utf-8");            BitMatrix bitMatrix = new QRCodeWriter().encode(text,                    BarcodeFormat.QR_CODE, size, size, hints);            int[] pixels = new int[size * size];            for (int y = 0; y < size; y++) {                for (int x = 0; x < size; x++) {                    if (bitMatrix.get(x, y)) {                        pixels[y * size + x] = 0xff000000;                    } else {                        pixels[y * size + x] = 0xffffffff;                    }                }            }            Bitmap bitmap = Bitmap.createBitmap(size, size,                    Bitmap.Config.ARGB_8888);            bitmap.setPixels(pixels, 0, size, 0, 0, size, size);            return bitmap;        } catch (WriterException e) {            e.printStackTrace();            return null;        }    }
0 0
原创粉丝点击