0

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
    }
Sean Owen
  • 66,182
  • 23
  • 141
  • 173
Mansi
  • 1,939
  • 4
  • 22
  • 40

3 Answers3

1

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.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
0

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! :)

-1

Substitute with the following:

BitMatrix bitMatrix = new Code128Writer().write( "ABC-abc-1234",
                                                 BarcodeFormat.CODE_128,
                                                 350,
                                                 150,
                                                 hints
                                                 );
user3666197
  • 1
  • 6
  • 50
  • 92
Jason
  • 1
  • I can't find .write() method from Code128Writer class. – shkim Oct 12 '15 at 15:31
  • Yeah - you use encode() but that does not add the text like you're looking for either. I'm trying to solve the same problem. Given that someone said that ZXing doesn't display text, I took a quick look at the source and indeed I found nothing. – humanity Apr 07 '16 at 18:14