当前位置: 代码迷 >> Web前端 >> 依据内容生产条1维形码
  详细解决方案

依据内容生产条1维形码

热度:586   发布时间:2012-07-31 12:33:46.0
根据内容生产条1维形码
BarCode.jar包 ,将内容转换为1维条码
public static  byte [] createBarCode(String content){ 
    if(content==null){ 
    return null; 
    } 
    ByteArrayOutputStream out=null; 
    try 
{ 
    out=new ByteArrayOutputStream(); 
    Code39Bean bean = new Code39Bean(); 
    final int dpi = 150; 
    bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); 
bean.setWideFactor(3); 
         bean.doQuietZone(false); 
         BitmapCanvasProvider canvas = new BitmapCanvasProvider(out// 
                                 ,"image/jpeg"// 
                           ,dpi// 
                           ,BufferedImage.TYPE_BYTE_BINARY// 
                           ,false// 
                           ,0); 
    bean.generateBarcode(canvas, content); 
    canvas.finish(); 
    return out.toByteArray(); 
    
} catch (IOException e) 
{ 
throw new  RuntimeException("创建条形码失败!"); 

}finally{ 
  if(out!=null){ 
try 
{ 
   out.close(); 
} catch (IOException e) 
{ 
throw new  RuntimeException("资源不能正常关闭!"); 
} 

  } 
} 
    }

  相关解决方案