Java 类com.google.zxing.oned.Code128Writer 实例源码

项目:STAR-Vote    文件:PrintImageUtils.java   
/**
 * A method for generating a barcode of some text
 *
 * @param string        the string to be converted to barcode, will be a bid in this case
 * @return              an image representing the barcode to be drawn on a ballot
 */
public static BufferedImage getBarcode(String string){

    /* Try to encode the string as a barcode */
    try {

        Code128Writer writer = new Code128Writer();
        BitMatrix bar = writer.encode(string, BarcodeFormat.CODE_128, 264, 48, new HashMap<EncodeHintType,Object>());

        return MatrixToImageWriter.toBufferedImage(bar);
    }
    catch (WriterException e){ throw new RuntimeException(e); }

}
项目:elexis-3-base    文件:Barcode.java   
public BufferedImage getCode128(String strCode128) {

                BitMatrix bitMatrix;

                try {
        //  Write Barcode

                    bitMatrix = new Code128Writer().encode(strCode128, BarcodeFormat.CODE_128, 195, 40, null);

                    MatrixToImageWriter.toBufferedImage(bitMatrix);
//                  System.out.println("Code128 Barcode Generated.");

                    return MatrixToImageWriter.toBufferedImage(bitMatrix);

                } catch (Exception e) {

                    System.out.println("Exception Found." + e.getMessage());

                }
                return null;

            }