日期:2014-05-18  浏览次数:20790 次

JAVA开发条形码问题
上班一周   老大叫弄个JAVA关于条码的小例子   大概意思是   输入几个数字   然后点提交   自动转成   CODE为   128   的条形码   然后通过条码机   打印出来。没这方面的知识   希望指点下。最好给我个小例子...非常感谢。

------解决方案--------------------
建议使用barcode4j
public File genBarCode(String message,String type,int height,int mw,int wf,String fmt,int res,boolean gray)
{
File outputFile = new File(message+ ".png ");
try {
Code128Bean bean128 = new Code128Bean();

final int dpi = 150;
bean128.setModuleWidth(UnitConv.in2mm(1.5f / dpi));
bean128.setHeight(8);
bean128.doQuietZone(false);

OutputStream out = new FileOutputStream(outputFile);

try {
//Set up the canvas provider for monochrome JPEG output
BitmapCanvasProvider canvas = new BitmapCanvasProvider(
out, "image/png ", dpi, BufferedImage.TYPE_BYTE_BINARY, false);

//Generate the barcode
bean128.generateBarcode(canvas, message);

//Signal end of generation
canvas.finish();

} finally {
out.close();
}
} catch (Exception e) {
e.printStackTrace();
}

return outputFile;
}
--这个是生成条形码图片的代码,至于条码机打印,就是后话了
------解决方案--------------------
网上有人开发好的
------解决方案--------------------
这个应该有现成的函数库可供使用。
Mark!
------解决方案--------------------
没做过,顶贴
------解决方案--------------------
网上应该有生成条形码的c程序或是其他语言编写的程序,让后用jni进行调用就可以了吧