Data too big for QR Code Generation with XZing in Android with Java


I am trying to generate a QR Code and set it to an ImageView out of a PGP Public Key in my Android Application with Java. The libary I use is XZing and I am on Android Studio. This worked well before with smaller Strings, however when I try to do it with something as big as a PGP Public Key I get this error: Data too big

So my data is too big. Is there any possibility to create a QR Code with a String this big in XZing?

I have tried it with two different methods but both lead to the same exception.

Method one:

    private void generateQR(String value) {

      QRGEncoder qrgEncoder = new QRGEncoder(value, null, QRGContents.Type.TEXT, 1000);

        try {
            // Getting QR-Code as Bitmap
            Bitmap bm = qrgEncoder.encodeAsBitmap();


            // Setting Bitmap to ImageView
        } catch (WriterException e) {
            Log.v(TAG, e.toString());

Method two:

private Bitmap textToImage(String text, int width, int height) throws WriterException, NullPointerException {
        BitMatrix bitMatrix;
        try {
            bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.DATA_MATRIX.QR_CODE,
                    width, height, null);
        } catch (IllegalArgumentException Illegalargumentexception) {
            return null;

        int bitMatrixWidth = bitMatrix.getWidth();
        int bitMatrixHeight = bitMatrix.getHeight();
        int[] pixels = new int[bitMatrixWidth * bitMatrixHeight];

        int colorWhite = 0xFFFFFFFF;
        int colorBlack = 0xFF000000;

        for (int y = 0; y < bitMatrixHeight; y++) {
            int offset = y * bitMatrixWidth;
            for (int x = 0; x < bitMatrixWidth; x++) {
                pixels[offset + x] = bitMatrix.get(x, y) ? colorBlack : colorWhite;
        Bitmap bitmap = Bitmap.createBitmap(bitMatrixWidth, bitMatrixHeight, Bitmap.Config.ARGB_4444);

        bitmap.setPixels(pixels, 0, width, 0, 0, bitMatrixWidth, bitMatrixHeight);
        return bitmap;
asked on Stack Overflow Jul 4, 2020 by AztecCodes • edited Jul 4, 2020 by Aderoju Israel

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0