【问题标题】:zxing barcode not displaying any textzxing条码不显示任何文字
【发布时间】:2016-10-05 09:52:14
【问题描述】:

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

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
}

【问题讨论】:

    标签: barcode zxing


    【解决方案1】:

    也许帮助你已经晚了,但我遇到了同样的问题,并且能够在 C# 中解决以下问题

    var barcodeWriter = new BarcodeWriter
    {
        Format = BarcodeFormat.CODE_128,
        Options = new EncodingOptions
        {
            Height = 160,
            Width = 300,
            Margin = 0,
            PureBarcode = false
        },
        Renderer = new BitmapRenderer()
        {
            TextFont = new Font(FontFamily.GenericSerif, 15)
        }
    };
    
    var bitmap = barcodeWriter.Write("your content");
    bitmap.Save(@"C:\\FULL\PATH\FILE.JPG");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多