java中条形码的各种编码格式,OkapiBarcode

Okapi Barcode license-Apache%202-blue.svgbadge.svgOkapiBarcode.svg?branch=masterbadge.svg

Okapi Barcode is an open-source barcode generator written entirely in Java,

supporting over 50 encoding standards, including all ISO standards. Okapi

Barcode is based on Zint, an

open-source barcode encoding library developed in C, and builds on the years

of work that have been invested in that project.

Supported Symbologies

Australia Post variants:

Standard Customer

Reply Paid

Routing

Redirection

Code 2 of 5 variants:

Matrix 2 of 5

Industrial 2 of 5

IATA 2 of 5

Datalogic 2 of 5

Interleaved 2 of 5

ITF-14

Deutsche Post Leitcode

Deutsche Post Identcode

Code 32 (Italian pharmacode)

EAN variants:

EAN-13

EAN-8

GS1 DataBar variants:

GS1 DataBar

GS1 DataBar Stacked

GS1 DataBar Stacked Omnidirectional

GS1 DataBar Expanded variants:

GS1 DataBar Expanded

GS1 DataBar Expanded Stacked

MSI (Modified Plessey)

PDF417 variants:

PDF417

Truncated PDF417

Micro PDF417

Telepen variants:

Telepen

Telepen Numeric

UPC variants:

UPC-A

UPC-E

USPS OneCode (Intelligent Mail)

Library Usage

To generate barcode images in your own code using the Okapi Barcode library, use one of the symbology

classes linked above:

instantiate the class,

customize any relevant settings,

invoke setContent(String), and then

pass the symbol instance to one of the available symbol renderers

(Java 2D,

PostScript,

SVG)

Code128 barcode = new Code128();

barcode.setFontName("Monospaced");

barcode.setFontSize(16);

barcode.setModuleWidth(2);

barcode.setBarHeight(50);

barcode.setHumanReadableLocation(HumanReadableLocation.BOTTOM);

barcode.setContent("123456789");

int width = barcode.getWidth();

int height = barcode.getHeight();

BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY);

Graphics2D g2d = image.createGraphics();

Java2DRenderer renderer = new Java2DRenderer(g2d, 1, Color.WHITE, Color.BLACK);

renderer.render(barcode);

ImageIO.write(image, "png", new File("code128.png"));

Okapi Barcode JARs are available for download from Maven Central.

GUI Usage

To use the Swing GUI, just run the OkapiUI class.

The GUI allows you to explore the supported barcode symbologies and test them with different configurations

and data.

42a3f2b9ad13f329b9f3ed54075bfdef.png

Building

gradlew check: Compiles and runs all quality checks, including the unit tests.

gradlew jar: Builds the JAR file.

gradlew uploadArchives: Deploys to Maven Central (requires a modified gradle.properties file).

NOTE: The unit tests should all pass under Oracle JDK, but will probably not all pass under OpenJDK. The tests verify barcode rendering image output, and the output images generated by OpenJDK are a bit different from the output images generated by the Oracle JDK (because their 2D graphics and font subsystems are slightly different).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值