当前位置: 首页 > 工具软件 > JBarcode > 使用案例 >

java 条形码_Java使用jbarcode生成条形码详解

仉洲
2023-12-01

java生成条形码需要jbarcode包,引用此包之后就可以很方便的生成条形码了。

如下代码实现:

import java.awt.image.BufferedImage;

import java.io.FileOutputStream;

import org.jbarcode.JBarcode;

import org.jbarcode.encode.EAN8Encoder;

import org.jbarcode.paint.EAN8TextPainter;

import org.jbarcode.paint.WidthCodedPainter;

import org.jbarcode.util.ImageUtil;

/**

* 2012-05-28

* @author 郏高阳

* 支持EAN13, EAN8, UPCA, UPCE, Code 3 of 9, Codabar, Code 11, Code 93, Code 128, MSI/Plessey, Interleaved 2 of PostNet等

* 利用jbarcode生成各种条形码!测试成功!分享给大家!

*/

public class OneBarcodeUtil {

public static void main(String[] paramArrayOfString) {

try {

JBarcode localJBarcode = new JBarcode(EAN8Encoder.getInstance(),WidthCodedPainter.getInstance(),EAN8TextPainter.getInstance());

String str = "2219644";

BufferedImage localBufferedImage = localJBarcode.createBarcode(str);

saveToGIF(localBufferedImage, "EAN8.jpg");

}

catch (Exception localException) {

localException.printStackTrace();

}

}

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("C:\\Users\\Administrator\\Desktop/" + paramString1);

ImageUtil.encodeAndWrite(paramBufferedImage, paramString2, localFileOutputStream, 96, 96);

localFileOutputStream.close();

}

catch (Exception localException) {

localException.printStackTrace();

}

}

}

 类似资料: