二维码扫描乱码的问题解决方法
来源:互联网 发布:台企怎么样知乎 编辑:程序博客网 时间:2024/06/06 07:06
如果有中文的字符串生成二维码被扫描,会扫描出乱码。本人在网上搜了各种资料都不管用,最后终于让我试验成功,记录下来,希望对大家有所帮助!
public final class CreateEncoding { private static final int BLACK = 0xff000000; public static Bitmap createQRCode(String str, int widthAndHeight) throws WriterException { Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); hints.put(EncodeHintType.MARGIN, 1); // BitMatrix matrix = new MultiFormatWriter().encode(str, // BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight); BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, widthAndHeight, widthAndHeight,hints); int margin = 5; // 自定义白边边框宽度 matrix = updateBit(matrix, margin); // 生成新的bitMatrix 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] = BLACK; } } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; } private static BitMatrix updateBit(BitMatrix matrix, int margin) { int tempM = margin * 2; int[] rec = matrix.getEnclosingRectangle(); // 获取二维码图案的属性 int resWidth = rec[2] + tempM; int resHeight = rec[3] + tempM; BitMatrix resMatrix = new BitMatrix(resWidth, resHeight); // 按照自定义边框生成新的BitMatrix resMatrix.clear(); for (int i = margin; i < resWidth - margin; i++) { // 循环,将二维码图案绘制到新的bitMatrix中 for (int j = margin; j < resHeight - margin; j++) { if (matrix.get(i - margin + rec[0], j - margin + rec[1])) { resMatrix.set(i, j); } } } return resMatrix; }}
0 0
- 二维码扫描乱码的问题解决方法
- android程序中Zxing二维码扫描图片变形 问题解决方法
- android程序中Zxing二维码扫描图片变形 问题解决方法
- 二维码中文乱码问题解决
- # Zxing二维码扫描图片预览变形的问题解决
- ios扫描二维码方法
- iOS扫描二维码方法
- 关于使用ZXing扫描二维码出现中文乱码的问题
- iOS 使用Zbar 二维码扫描的时候, 出现中文乱码
- 关于使用ZXing扫描二维码出现中文乱码的问题
- 二维码扫描匡大小、扫描旋转。扫描拉伸问题解决
- 二维码的扫描
- 二维码的扫描、生成
- iOS的二维码扫描
- 二维码的扫描--iOS
- 二维码的生成/扫描
- 二维码的扫描
- 二维码的扫描
- win7彻底解决COM端口被占用(在使用中)问题的办法
- MYSQL下载及重装的步骤
- DLL入门浅析(5)——使用DLL在进程间共享数据
- G. 易彰彪的一张表(kMP)
- Tomcat如何实现资源安全管理
- 二维码扫描乱码的问题解决方法
- android中java与js通信(可以用html来做页面,进行交互)
- ubuntu14.04安装squirrelmail
- jQuery中ajax的使用和缓存问题解决
- Sql去除数据库中某一列的特殊字符
- LeetCode *** 211. Add and Search Word - Data structure design(字典树)
- iOS高级动画:圆形树展开&收起动画
- Openstack 中的zone ,aggregates和host及其应用
- COM技术入门基础知识