小编Gab*_*iel的帖子

如何使用Zxing缩短生成QR码的时间

我正在创建一个带有QR条码的应用程序.条形码正确加载,但不知怎的,加载有点慢,我点击/单击菜单后约3-5秒.

我们可以加快速度吗?或者页面加载那么长吗?其他部分加载仅需1秒或更短时间.该应用程序也离线,因此不需要互联网连接.

这里我的代码生成QR条码:

ImageView imageViewBarcode = (ImageView)findViewById(R.id.imageViewBarcode);

    try {
        bitmap = TextToImageEncode(barcode_user);

        imageViewBarcode.setImageBitmap(bitmap);

    } catch (WriterException e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

上面的代码放在onCreate中.所以当页面加载时,它会生成条形码.

这里创建条形码的功能

Bitmap TextToImageEncode(String Value) throws WriterException {
    BitMatrix bitMatrix;
    try {
        bitMatrix = new MultiFormatWriter().encode(
                Value,
                BarcodeFormat.DATA_MATRIX.QR_CODE,
                QRcodeWidth, QRcodeWidth, null
        );

    } catch (IllegalArgumentException Illegalargumentexception) {

        return null;
    }
    int bitMatrixWidth = bitMatrix.getWidth();

    int bitMatrixHeight = bitMatrix.getHeight();

    int[] pixels = new int[bitMatrixWidth * bitMatrixHeight];

    for (int y = 0; y < bitMatrixHeight; y++) {
        int offset = y * …
Run Code Online (Sandbox Code Playgroud)

android qr-code

3
推荐指数
1
解决办法
1126
查看次数

标签 统计

android ×1

qr-code ×1