2016-10-05 56 views
1

我使用斑馬線庫由條碼生成,但是當條碼生成那麼下面條碼不會顯示的文字像斑馬線條形碼不顯示任何文本

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 
} 

enter image description here

回答

0

也許是晚來幫助你,但我經歷了同樣的問題,並能夠解決以下在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");