java生成条形码(多种条码类型生成)

//需下载jbarcode.jar包
//创建EAN13条码格式
//strCodes为条码
 public BufferedImage  getEAN13Image(String strCodes){
 try  
     {  
       JBarcode localJBarcode = new JBarcode(EAN13Encoder.getInstance(), WidthCodedPainter.getInstance(), EAN13TextPainter.getInstance());  
       //生成. 欧洲商品条码(=European Article Number)  
       //这里我们用作图形条码
       BufferedImage localBufferedImage = localJBarcode.createBarcode(strCodes);
       return localBufferedImage;
     }  
     catch (Exception localException)  
     {  
       localException.printStackTrace();  
     }  
     return null;
   }  
 //创建EAN8条码格式
 public BufferedImage getEAN8Image(String strCodes){
 try  
     {  
       JBarcode localJBarcode = new JBarcode(EAN8Encoder.getInstance(), WidthCodedPainter.getInstance(), EAN8TextPainter.getInstance());  
       //生成. 欧洲商品条码(=European Article Number)  
       //这里我们用作图形条码
       BufferedImage localBufferedImage = localJBarcode.createBarcode(strCodes);
       return localBufferedImage;
     }  
     catch (Exception localException)  
     {  
       localException.printStackTrace();  
     }  
     return null;
   }
 //创建UPC-A条码格式
 public BufferedImage getUPCAImage(String strCodes){
 try  
     {  
       JBarcode localJBarcode = new JBarcode(UPCAEncoder.getInstance(), WidthCodedPainter.getInstance(), UPCATextPainter.getInstance());  
       //生成. 欧洲商品条码(=European Article Number) 
       //这里用作图形条码
       BufferedImage localBufferedImage = localJBarcode.createBarcode(strCodes);
       return localBufferedImage;  
     }  
     catch (Exception localException)  
     {  
       localException.printStackTrace();  
     }  
 return null;
   }


你可能感兴趣的:(java生成条形码(多种条码类型生成))