【问题标题】:android : BarcodeFormat.CODE_128 not displaying textandroid:BarcodeFormat.CODE_128 不显示文本
【发布时间】:2014-02-26 12:17:20
【问题描述】:

我使用 ZXing Library 制作了条码生成器,但是当条码生成时,它不会在条码下方显示文本

所以请建议我一些解决方案,如何使用 TEXT 生成 BARCODE CODE_128 这是我的代码:

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
    }

【问题讨论】:

    标签: android barcode zxing encode code128


    【解决方案1】:

    编码器不会在图像中添加任何额外的文本。其目的仅是生成条形码。您必须将其添加到其他地方。

    【讨论】:

      【解决方案2】:

      致任何仍在寻找问题解决方案的人。一种可能的方法是为条形码创建一个位图图像,为条形码下方的信息创建另一个。然后您可以组合/叠加或根据需要将两个位图合二为一并打印组合的位图!经兄弟 LQ-720NW 测试,一切正常! :)

      【讨论】:

        【解决方案3】:

        替换为以下内容:

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

        【讨论】:

        • 我在 Code128Writer 类中找不到 .write() 方法。
        • 是的 - 您使用 encode() 但这也不会像您正在寻找的那样添加文本。我正在尝试解决同样的问题。鉴于有人说ZXing不显示文字,我快速浏览了一下来源,确实没有找到。
        猜你喜欢
        • 1970-01-01
        • 2019-03-27
        • 2017-04-24
        • 2019-02-05
        • 2021-09-15
        • 1970-01-01
        • 1970-01-01
        • 2014-12-23
        • 2014-10-26
        相关资源
        最近更新 更多