JBarcodeBean 生成条形码 并拼接图片

[url]http://my.oschina.net/ruibo/blog/546364[/url]


查了好多博客 好多都用的 EAN8/EAN13/Code39 后来发现生成的条形码都不能把 数字显示完成 就改为了code128
JBarcodeBean jBarcodeBean = new JBarcodeBean();
jBarcodeBean.setCodeType(new Code128());
jBarcodeBean.setCode("301010025000001877");
BufferedImage img1 = new BufferedImage(300, 100,
BufferedImage.TYPE_INT_RGB);
img1 = jBarcodeBean.draw(img1);
saveToPNG(img1, "4.png");

static void saveToJPEG(BufferedImage paramBufferedImage, String paramString) {
saveToFile(paramBufferedImage, paramString, "jpeg");
}
static void saveToFile(BufferedImage paramBufferedImage,
String paramString1, String paramString2) {
try {
FileOutputStream localFileOutputStream = new FileOutputStream(
"d:/test/" + paramString1);
ImageUtil.encodeAndWrite(paramBufferedImage, paramString2,
localFileOutputStream, 100, 100);
localFileOutputStream.close();
} catch (Exception localException) {
localException.printStackTrace();
}
}

因为有需要把生成的条形码 拼接在一个图片里 保存
public byte[] getJabCode(String code) throws IOException{
//String code="301010025000001877,301010025000001878";
String[] args=code.split("\\,");
JBarcodeBean jBarcodeBean = new JBarcodeBean();
jBarcodeBean.setLabelPosition(JBarcodeBean.LABEL_BOTTOM);
// 条形码类型
jBarcodeBean.setCodeType(new Code128());
// jBarcodeBean.setCodeType(new Code39());
//jBarcodeBean1.setLabelPosition(JBarcodeBean.LABEL_BOTTOM);
int width1=200;
int height1 =100;
BufferedImage imageNew1 = new BufferedImage(width1, height1*args.length ,
BufferedImage.TYPE_INT_RGB);

for(int i=0;i<args.length;i++){
jBarcodeBean.setCode(args[i]);
BufferedImage tempimg = new BufferedImage(width1, height1,
BufferedImage.TYPE_INT_RGB);
tempimg = jBarcodeBean.draw(tempimg);
int[] ImageArrayOne1 = new int[width1 * height1];
ImageArrayOne1 = tempimg.getRGB(0, 0, width1, height1, ImageArrayOne1, 0,
width1);
imageNew1.setRGB(0, 100*i, width1, height1, ImageArrayOne1, 0, width1);

}
ByteArrayOutputStream out = new ByteArrayOutputStream();
boolean flag = ImageIO.write(imageNew1, "gif", out);
byte[] b = out.toByteArray();
//saveToPNG(imageNew1, "imageNew1.png");
return b;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值