建议使用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;
}
--这个是生成条形码图片的代码,至于条码机打印,就是后话了
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;
}
--这个是生成条形码图片的代码,至于条码机打印,就是后话了
解决方案 »
- 项目在Linux下报ExceptionInInitializerError
- JSP页面播放器
- java 如何创建ftp多层目录
- 菜鸟的~hibernate 存储问题.求助.......~~~~~~~~~~感谢!~~~~~~~~~~~~~~~
- JDBC对数据库操作
- struts 中Cannot find bean name in any scope错误
- 刚开始学webservice多多指教!
- 如果一个mdb文件中有表a,b,c,d。如何用连接Access的connecton将所有表取出?
- 请问struts1.0中,如何对表单进行验证?
- 大家怎么解决eclipse使用template的问题的啊?
- Cannot find bean under name org.apache.struts.taglib.html.BEAN 问题,困扰了很久了
- web.xml配置org.springframework.web.context.ContextLoaderListener监听器出错
(2)识别和转换:有条形码的开源组件。google吧,有很多不同的规范,这个基本已经很成熟了
最近正好需要相關知識