1. 程式人生 > >將文字轉成二維碼

將文字轉成二維碼

jar包下載地址:
http://files.cnblogs.com/files/lee0oo0/%E4%BA%8C%E7%BB%B4%E7%A0%81Jar%E5%8C%85.rar
private Bitmap generateBitmap(String content,int width, int height) {
    QRCodeWriter qrCodeWriter = new QRCodeWriter();
    Map<EncodeHintType, String> hints = new HashMap<>();
    hints.put(EncodeHintType.CHARACTER_SET
, "utf-8"); try { BitMatrix encode = qrCodeWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints); int[] pixels = new int[width * height]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (encode.get(j, i)) { pixels[i * width + j] = 0x00000000
; } else { pixels[i * width + j] = 0xffffffff; } } } return Bitmap.createBitmap(pixels, 0, width, width, height, Bitmap.Config.RGB_565); } catch (WriterException e) { e.printStackTrace(); } return null; }