2014-04-25 32 views
0

此代碼創建BarCode圖像以及圖像下方的文本。 我需要從圖像中刪除文字。 Code39Bean沒有任何屬性來禁用此功能。在Code39Bean中的條碼圖像下方禁用文本

public static ByteArrayOutputStream generateBarcodeImg(String inputId) 
      throws Exception { 

     ByteArrayOutputStream baos = new ByteArrayOutputStream(); 

     Code39Bean bean = new Code39Bean(); 
     final int dpi = 150; 

     /** 
     * Configure the bar-code generator and makes the narrow bar width 
     * exactly one pixel. 
     */ 
     bean.setModuleWidth(UnitConv.in2mm(1.0f/dpi)); 
     bean.setWideFactor(3); 
     bean.doQuietZone(false); 

     try { 

      /** Set up the canvas provider for monochrome PNG output. */ 
      BitmapCanvasProvider canvas = new BitmapCanvasProvider(baos, 
        BarCodeConstant.CONTENT_TYPE, dpi, 
        BufferedImage.TYPE_BYTE_BINARY, false, 0); 

      /** Generate the bar code. */ 
      bean.generateBarcode(canvas, inputId); 

      /** Signal end of generation. */ 
      canvas.finish(); 
     } catch (IOException e) { 
      logger.error(
        "Exception occured in BarcodeGeneration: generateBarcodeImg " 
          + e.getLocalizedMessage(), e); 
      throw new MobileResourceException(
        "Exception occured in BarcodeGeneration: generateBarcodeImg", 
        null); 
     } 
     return baos; 

    } 
} 

回答

1

您可以通過「HumanReadablePlacement」屬性中刪除從圖片文字:

bean.setMsgPosition(HumanReadablePlacement.HRP_NONE); 

這將打壓條形碼爲NONE的人類可讀的文本。