嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
把生成的条形码 拼接在一个图片里 保存
public class test {
public static void singleCode()
{
JBarcodeBean jBarcodeBean = new JBarcodeBean();
jBarcodeBean.setCodeType(new Code128());
jBarcodeBean.setCode("1909240001");
BufferedImage img1 = new BufferedImage(300, 100,
BufferedImage.TYPE_INT_RGB);
img1 = jBarcodeBean.draw(img1);
saveToJPEG(img1, "imageNeww2.jpeg");
}
public static void main(String[] args) throws Exception {
String code="301010025000001877,301010025000001878";
// singleCode();
// getJabCode(code);
System.out.println(getJabCode(code));
}
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:/barcode/" paramString1);
ImageUtil.encodeAndWrite(paramBufferedImage, paramString2,
localFileOutputStream, 100, 100);
localFileOutputStream.close();
} catch (Exception localException) {
localException.printStackTrace();
}
}
public static 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");
saveToJPEG(imageNew1, "imageNew1.jpeg");
return b;
}
}