package com.wl.cn.business.express.util;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import org.jbarcode.JBarcode;
import org.jbarcode.encode.Code128Encoder;
import org.jbarcode.paint.BaseLineTextPainter;
import org.jbarcode.paint.WideRatioCodedPainter;
import org.jbarcode.paint.WidthCodedPainter;
import org.jbarcode.util.ImageUtil;
public class PrintBarcodeUtil {
public static ByteArrayOutputStream getPrintBarcodeUtil(String str){
try {
JBarcode localJBarcode = new JBarcode(Code128Encoder.getInstance(),
WidthCodedPainter.getInstance(),
BaseLineTextPainter.getInstance());
BufferedImage localBufferedImage = localJBarcode.createBarcode(str);
//saveToPNG(localBufferedImage, "Test.png");
ByteArrayOutputStream bt=saveToFile(localBufferedImage, "Code128Encoder", "png");
localJBarcode.setEncoder(Code128Encoder.getInstance());
localJBarcode.setPainter(WideRatioCodedPainter.getInstance());
localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());
localJBarcode.setShowCheckDigit(false);
// xx
str = "JBARCODE-39";
localBufferedImage = localJBarcode.createBarcode(str);
return bt;
} catch (Exception localException) {
localException.printStackTrace();
}
return null;
}
static ByteArrayOutputStream saveToFile(BufferedImage paramBufferedImage,
String paramString1, String paramString2) {
ByteArrayOutputStream localFileOutputStream=null;
try {
localFileOutputStream = new ByteArrayOutputStream();
ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96);
} catch (Exception localException) {
localException.printStackTrace();
}
return localFileOutputStream;
}
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import org.jbarcode.JBarcode;
import org.jbarcode.encode.Code128Encoder;
import org.jbarcode.paint.BaseLineTextPainter;
import org.jbarcode.paint.WideRatioCodedPainter;
import org.jbarcode.paint.WidthCodedPainter;
import org.jbarcode.util.ImageUtil;
public class PrintBarcodeUtil {
public static ByteArrayOutputStream getPrintBarcodeUtil(String str){
try {
JBarcode localJBarcode = new JBarcode(Code128Encoder.getInstance(),
WidthCodedPainter.getInstance(),
BaseLineTextPainter.getInstance());
BufferedImage localBufferedImage = localJBarcode.createBarcode(str);
//saveToPNG(localBufferedImage, "Test.png");
ByteArrayOutputStream bt=saveToFile(localBufferedImage, "Code128Encoder", "png");
localJBarcode.setEncoder(Code128Encoder.getInstance());
localJBarcode.setPainter(WideRatioCodedPainter.getInstance());
localJBarcode.setTextPainter(BaseLineTextPainter.getInstance());
localJBarcode.setShowCheckDigit(false);
// xx
str = "JBARCODE-39";
localBufferedImage = localJBarcode.createBarcode(str);
return bt;
} catch (Exception localException) {
localException.printStackTrace();
}
return null;
}
static ByteArrayOutputStream saveToFile(BufferedImage paramBufferedImage,
String paramString1, String paramString2) {
ByteArrayOutputStream localFileOutputStream=null;
try {
localFileOutputStream = new ByteArrayOutputStream();
ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96);
} catch (Exception localException) {
localException.printStackTrace();
}
return localFileOutputStream;
}
}
//我是生成后放入流中,自己试验可以放入到一个fileout中