1 import java.awt.image.BufferedImage; 2 import java.io.FileOutputStream; 3 import org.jbarcode.JBarcode; 4 import org.jbarcode.encode.EAN8Encoder; 5 import org.jbarcode.paint.EAN8TextPainter; 6 import org.jbarcode.paint.WidthCodedPainter; 7 import org.jbarcode.util.ImageUtil; 8 /** 9 * 支持EAN13, EAN8, UPCA, UPCE, Code 3 of 9, Codabar, Code 11, Code 93, Code 128, MSI/Plessey, Interleaved 2 of PostNet等10 * 利用jbarcode生成各种条形码!测试成功!分享给大家!11 */ 12 public class OneBarcodeUtil { 13 14 public static void main(String[] paramArrayOfString) { 15 try { 16 JBarcode localJBarcode = new JBarcode(EAN8Encoder.getInstance(),WidthCodedPainter.getInstance(),EAN8TextPainter.getInstance()); 17 String str = "2219644"; 18 BufferedImage localBufferedImage = localJBarcode.createBarcode(str); 19 20 saveToGIF(localBufferedImage, "EAN8.jpg");21 } 22 catch (Exception localException) { 23 localException.printStackTrace(); 24 } 25 } 26 27 static void saveToJPEG(BufferedImage paramBufferedImage, String paramString) { 28 saveToFile(paramBufferedImage, paramString, "jpeg"); 29 } 30 31 static void saveToFile(BufferedImage paramBufferedImage, String paramString1, String paramString2) { 32 try { 33 FileOutputStream localFileOutputStream = new FileOutputStream("C:\\Users\\Administrator\\Desktop/" + paramString1); 34 ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96); 35 localFileOutputStream.close(); 36 } 37 catch (Exception localException) { 38 localException.printStackTrace(); 39 } 40 } 41 }