我需要128A格式的數據來生成條碼條碼生成:900000588548001100001305000000000207201512345.6 | 12345.7故障使用斑馬線庫大數據
我使用斑馬線庫,這裏是我的方法:
private void barcodeGenerator(String data)
{
try
{
com.google.zxing.MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix bm = writer.encode(data, BarcodeFormat.CODE_128, 700, 200);
Bitmap ImageBitmap = Bitmap.createBitmap(700, 200, Config.ARGB_8888);
for (int i = 0; i < 700; i++)
{//width
for (int j = 0; j < 200; j++)
{//height
ImageBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK : Color.WHITE);
}
}
File f = new File(Environment.getExternalStorageDirectory() + "/barcode1.png");
FileOutputStream fos = new FileOutputStream(f);
ImageBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
}
catch(Exception e)
{
e.printStackTrace();
}
}
這方法生成條形碼圖像並將其存儲在使用ZXing條形碼掃描儀掃描的SD卡中。
當數據很小時,條碼掃描成功。如:123.4 | 456.7
但是,如果數據量大,如:900000588548001100001305000000000207201512345.6 | 12345.7
它看起來像會產生一些錯誤的條形碼和掃描儀無法掃描生成的條形碼。
預先感謝幫助。
編輯:有沒有添加生成的條形碼圖片
由於業務需求,我不能選擇QR碼,附上生成的條碼圖片,看看。 – Sneharc
該圖像是一個有效的Code 128條形碼,可以通過在線zxing解碼器讀取。我的手機無法閱讀,除非我打開圖像並將其縮放,以便在我的顯示器上顯示出來。在這篇文章中顯示的大小上,黑線太薄而無法成功解碼。 – BrentM
是的,你說得對。當我將長度增加到1000時,我可以正確掃描它。謝謝! – Sneharc