Question

I made Barcode generator using ZXing Library but when barcode generate then it wont display text below barcode like

enter image description here

so please suggest me some solution that how to generate BARCODE CODE_128 with TEXT Here it my code:

try {

        Map<EncodeHintType, Object> hints = null;
        hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hints.put(EncodeHintType.CHARACTER_SET, "ABC-abc-1234");

        BitMatrix bitMatrix = new Code128Writer().encode("ABC-abc-1234", BarcodeFormat.CODE_128, 350, 150, hints);

        int width = bitMatrix.getWidth();
        int height = bitMatrix.getHeight();
        int[] pixels = new int[width * height];
        // All are 0, or black, by default
        for (int y = 0; y < height; y++) {
            int offset = y * width;
            for (int x = 0; x < width; x++) {
                pixels[offset + x] = bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE;
            }
        }

        Bitmap bitmap = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
        mImageView.setImageBitmap(bitmap);
    } catch (Exception e) {
        // TODO: handle exception
    }

No correct solution

OTHER TIPS

The encoder does not put any additional text into the image. Its purpose is to generate the barcode only. You would have to add it elsewhere.

To anyone, who is still searching a solution to the problem. A possible one is to create one Bitmap image for the barcode and another one for the information below the barcode. Then you can just combine/overlay or as you want the two Bitmaps into one and print the combined Bitmap! Tested with Brother LQ-720NW, everything works fine! :)

Substitute with the following:

BitMatrix bitMatrix = new Code128Writer().write( "ABC-abc-1234",
                                                 BarcodeFormat.CODE_128,
                                                 350,
                                                 150,
                                                 hints
                                                 );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top