本文整理汇总了Java中com.google.zxing.oned.Code128Writer类的典型用法代码示例。如果您正苦于以下问题:Java Code128Writer类的具体用法?Java Code128Writer怎么用?Java Code128Writer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Code128Writer类属于com.google.zxing.oned包,在下文中一共展示了Code128Writer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBarcode
import com.google.zxing.oned.Code128Writer; //导入依赖的package包/类
/**
* 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); }
}
示例2: getCode128
import com.google.zxing.oned.Code128Writer; //导入依赖的package包/类
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;
}