1.条形码扫描识别的实现方法及步骤
本文以Java代码示例介绍如何来扫描和识别条形码图片。这里使用免费条码工具 Free Spire.Barcode for Java,调用BarcodeScanner类中的scan(java.lang.String fileName, BarCodeType barcodeType)方法扫描识别指定类型条码中包含的数据。在编辑代码前,先参考如下步骤手动将jar包导入Java程序:



完成导入:

【Java】
import com.spire.barcode.*; public class ScanBarcode { public static void main(String[] args)throws Exception{ String[] datas = BarcodeScanner.scan("EAN_13.png", BarCodeType.EAN_13); System.out.print(datas[0]); } }
执行程序,扫描识别条形码图片,获取条码中包含的数据:

2.条形码扫描的方法归纳
这里的BarcodeScanner类提供了多个扫描图片的方法,见下表1
表格1:
|
Method Summary |
|
|
static java.lang.String[] |
scan(java.awt.image.BufferedImage bitmap) |
|
Static java.lang.String[] |
scan(java.awt.image.BufferedImage image, BarCodeType barcodeType) |
|
Static java.lang.String[] |
scan(java.awt.image.BufferedImage bitmap,
java.awt.Rectangle rect, BarCodeType barcodeType) |
|
Static java.lang.String[] |
scan(java.io.InputStream stream) |
|
Static java.lang.String[] |
scan(java.io.InputStream stream,
boolean IncludeCheckSum) |
|
Static java.lang.String[] |
scan(java.lang.String fileName) |
|
Static java.lang.String[] |
scan(java.lang.String fileName, BarCodeType barcodeType) |
|
Static java.lang.String[] |
scan(java.lang.String fileName,
boolean IncludeCheckSum) |
|
Static java.lang.String |
scanOne(java.awt.image.BufferedImage bitmap) |
|
Static java.lang.String |
scanOne(java.io.InputStream stream) |
|
Static java.lang.String |
scanOne(java.io.InputStream stream,
boolean IncludeCheckSum) |
|
Static java.lang.String |
scanOne(java.lang.String fileName) |
|
Static java.lang.String |
scanOne(java.lang.String fileName,
boolean IncludeCheckSum) |
3. 条码生成及扫描类型汇总
因本次使用的是免费版的Barcode API,对支持生成的条码类型以及扫描的条码类型上有所限制,详细内容见下表2。在使用时,可根据自己的程序要求看条码类型是否支持。
表格-2:
|
条形码类型 |
生成的条形码类型 |
扫描条形码类型 |
|
CODE 25 |
× |
× |
|
CODABAR |
√ |
√ |
|
CODE 11 |
√ |
√ |
|
INTERLEAVED 25 |
× |
× |
|
CODE 39 |
√ |
√ |
|
CODE 39 EXTENDED |
√ |
√ |
|
CODE 93 |
√ |
√ |
|
CODE 93 EXTENDED |
√ |
√ |
|
CODE 128 |
√ |
√ |
|
EAN 8 |
√ |
√ |
|
EAN 13 |
√ |
√ |
|
EAN 128 |
√ |
× |
|
EAN 14 |
√ |
√ |
|
SCC 14 |
√ |
√ |
|
SSCC 18 |
× |
× |
|
ITF 14 |
× |
× |
|
ITF 6 |
× |
× |
|
UPCA |
× |
× |
|
UPCE |
× |
× |
|
POST NET |
√ |
× |
|
SINGAPORE POST 4 STATE |
× |
× |
|
PLANET |
× |
× |
|
MSI |
× |
× |
|
RSS 14 |
× |
× |
|
RSS 14 TRUNCATED |
× |
× |
|
RSS LIMITED |
× |
× |
|
RSS EXPANDED |
× |
× |
|
USPS |
× |
× |
|
SWISS POST PARCEL |
× |
× |
|
PZN |
× |
× |
|
OPC |
× |
× |
|
DEUTSCHE POST IDENTCODE |
× |
× |
|
DEUTSCHE POST LEITCODE |
× |
× |
|
ROYAL MAIL 4 STATE |
× |
× |
|
DATA MATRIX |
× |
× |
|
QR CODE |
√ |
× |
|
PDF 417 |
× |
× |
|
PDF 417 MACRO |
× |
× |
注释: √ 表示支持,× 表示不支持
—End—