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

    技术2025-04-28  18

    使用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;   }

    最新回复(0)