I need to generate barcode in 128A format with data: 900000588548001100001305000000000207201512345.6|12345.7
I'm using ZXing library and Here is my method:
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();
}
}
This method generates and stores the barcode image in SDCard which m scanning using ZXing Barcode Scanner.
Barcode is successfully scanned when data is small. eg: 123.4|456.7
But if data is large, eg: 900000588548001100001305000000000207201512345.6|12345.7
It looks like some wrong barcode is generated and Scanner is not able to scan the generated barcode.
Thanks in advance for help.
Edit: Have added generated barcode images
答案 0 :(得分:0)
您可以将您生成的条形码图像上传到ZXing Decoder Online,以确认它是否有效:
http://zxing.org/w/decode.jspx
Code 128 barcode的长度没有内在限制,您拥有的所有字符都有效。
话虽如此,使用Code 128A条形码,编码超过20个字符会使得条形码非常宽并且难以扫描。
条形码可能有效但扫描仪相机无法获得足够清晰的条形码图片。
请查看此问题以获取更多信息:Unable to scan Code 128
如果可能,建议使用替代条形码格式,例如QR码,它可以存储更多数据而不增加条形码大小。
答案 1 :(得分:0)
https://play.google.com/store/apps/details?id=com.srowen.bs.android android 应用程序扫描完美。但在生成条码的同时,尽量减少宽度和高度,以方便手机摄像头扫描。
我为 900000588548001100001305000000000207201512345.6|12345.7 重新生成了 CODE-128 条码,只有 300 和 150,它可以扫描,如果它不能按比例放大宽度和高度。 生成的条码:https://i.stack.imgur.com/UF0qJ.png