使用zxing原始碼內的encode方式,成功可以encode, decode了

本文介绍了一种利用ZXing库中的MultiFormatWriter类来生成QR码的方法,并提供了详细的源代码实现过程。通过该方法,可以将指定字符串内容转换为QR码图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用zxing原始碼內的encode方式,成功可以encode, decode了

private Bitmap encodeString(String input) {     try {       ByteMatrix result = new MultiFormatWriter().encode(input,           BarcodeFormat.QR_CODE, 300, 300);       int width = result.width();       int height = result.height();       byte[][] array = result.getArray();       int[] pixels = new int[width * height];       for (int y = 0; y < height; y++) {         for (int x = 0; x < width; x++) {           int grey = array[y][x] & 0xff;           //pixels[y * width + x] = (0xff << 24) | (grey << 16) | (grey << 8) | grey;           pixels[y * width + x] = 0xff000000 | (0x00010101 * grey);         }       }         Bitmap bitmap = Bitmap.createBitmap(width, height,           Bitmap.Config.ARGB_8888);       bitmap.setPixels(pixels, 0, width, 0, 0, width, height);       return bitmap;     } catch (WriterException e) {       Log.e(this.getClass().getName(), e.toString(), e);     }     return null;   }

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值