在這篇文章中,我們將討論如何使用 Java 創建條碼以及如何使用相同的 Java API 辨識條碼的細節。我們已經熟悉條碼是一種編碼標籤或標籤,放置在所有商品上,使電腦能夠更快且更準確地跟蹤和結帳商品。同樣,它們也可以輕鬆地印刷並及時添加到商品上,因此您的整個庫存都可以立即標記和跟蹤。此外,條碼提供自動產品識別、極快的識別和以非常低的錯誤率實施數據。這種方法是非常具有成本效益的,可以幫助雇主降低開支並縮短培訓時間和勞動力。

條碼生成 API

Aspose.BarCode Cloud 是一個 REST API,讓我們的客戶可以在編程中實現條碼生成和操作的功能。

該 API 能解析流行的光柵圖像格式。如需更多詳情,請訪問 Supported File Formats

生成帶有指定尺寸的條形碼

測試我們的 API 最快速且簡單的方法是使用 API 參考部分。 GetBarcodeGenerate 方法用於創建條形碼圖像,它提供了多種選項以根據您的需求生成條形碼,並且與特定參數相關的詳細資訊在 API 參考頁面上有很好的解釋。在生成條形碼時,您可以指定以下類型中的任一種

  • Codabar
  • Code11
  • Code39Standard
  • Code39Extended
  • Code93Standard
  • Code93Extended
  • Code128
  • GS1Code128
  • EAN8
  • EAN13
  • EAN14
  • SCC14
  • SSCC18
  • UPCA
  • UPCE
  • ISBN
  • ISSN
  • ISMN
  • Standard2of5
  • Interleaved2of5
  • Matrix2of5
  • ItalianPost25
  • IATA2of5
  • ITF14
  • ITF6
  • MSI
  • VIN
  • DeutschePostIdentcode
  • DeutschePostLeitcode
  • OPC
  • PZN
  • Code16K
  • 藥物編碼
  • DataMatrix
  • QR
  • Aztec
  • Pdf417
  • MacroPdf417
  • AustraliaPost
  • Postnet
  • 行星
  • OneCode
  • RM4SCC
  • DatabarOmniDirectional
  • DatabarTruncated
  • DatabarLimited
  • DatabarExpanded
  • SingaporePost
  • GS1DataMatrix
  • AustralianPosteParcel
  • SwissPostParcel
  • PatchCode
  • DatabarExpandedStacked
  • DatabarStacked
  • DatabarStackedOmniDirectional
  • MicroPdf417
  • GS1QR
  • MaxiCode
  • Code32
  • DataLogic2of5
  • DotCode
  • DutchKIX
  • UpcaGs1Code128Coupon
  • UpcaGs1DatabarCoupon
  • CodablockF
  • GS1CodablockF

cURL 命令

curl -X GET "https://api.aspose.cloud/v3.0/barcode/generate?Type=Codabar&Text=Hello%20World&TwoDDisplayText=QR&TextLocation=Above&TextAlignment=Center&TextColor=Blue&FontSizeMode=Auto&Resolution=96&TextSpace=2&Units=Point&SizeMode=Nearest&BarHeight=50&ImageHeight=200&ImageWidth=200&RotationAngle=0&BackColor=White&BorderDashStyle=Solid&SupplementData=EAN8&format=PNG" -H  "accept: image/png" -H  "authorization: Bearer <JWT Token>"

請求網址

https://api.aspose.cloud/v3.0/barcode/generate?Type=Codabar&Text=Hello%20World&TwoDDisplayText=QR&TextLocation=Above&TextAlignment=Center&TextColor=Blue&FontSizeMode=Auto&Resolution=96&TextSpace=2&Units=Point&SizeMode=Nearest&BarHeight=50&ImageHeight=200&ImageWidth=200&RotationAngle=0&BackColor=White&BorderDashStyle=Solid&SupplementData=EAN8&format=PNG

Java

以下代碼片段可用於生成條形碼圖像並將其儲存在雲端儲存中。

// 如需完整示例和數據文件,請前往 https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/

String name = "putBarcodeGenerateFile.png";
String type = EncodeBarcodeType.QR.getValue();
String text = "Put Barcode Generate File";
Double dimensionX = 200.0;

String twoDDisplayText = null;
String textLocation = null;
String textAlignment = null;
String textColor = null;
String fontSizeMode = null;
Double resolution = null;
Double textSpace = null;
String units = null;
String sizeMode = null;
Double barHeight = null;
Double imageHeight = null;
Double imageWidth = null;
Double rotationAngle = null;
String backColor = null;
String barColor = null;
String borderColor = null;
Double borderWidth = null;
String borderDashStyle = null;
Boolean borderVisible = null;
String enableChecksum = null;
Boolean enableEscape = null;
Boolean filledBars = null;
Boolean alwaysShowChecksum = null;
Double wideNarrowRatio = null;
Boolean validateText = null;
String supplementData = null;
Double supplementSpace = null;
String format = null;

String storage = "Storage";
String folder = "Temp/"

ResultImageInfo response =
		api.putBarcodeGenerateFile(
				name,type,text,twoDDisplayText,textLocation,textAlignment,textColor,fontSizeMode,
				resolution,null,null,dimensionX,textSpace,units,sizeMode,barHeight,
				imageHeight,imageWidth,rotationAngle,backColor,barColor,borderColor,borderWidth,
				borderDashStyle,borderVisible,enableChecksum,enableEscape,filledBars,
				alwaysShowChecksum,wideNarrowRatio,validateText,supplementData,
				supplementSpace,storage,folder,format);

assertTrue(response.getFileSize() > 0);
assertTrue(response.getImageWidth() > 0);
assertTrue(response.getImageHeight() > 0);
條形碼圖像

Image 1:- 使用 Java API 生成的條碼預覽

辨識光柵圖像中的條碼

該 API 還提供從光柵圖像文件識別條形碼的能力。圖像文件可以是 PNG、JPEG、BMP、GIF、TIFF 或 EXIF 格式。API 的 GetBarcodeRecognize 方法使您能夠完成此要求。名稱字段是必需的,其他可選字段提供了更好的識別操作能力,因為您可以指定條形碼類型信息、ChecksumValidation、編碼、允許配置識別質量和速度的預設等等。

cURL

curl -X GET "https://api.aspose.cloud/v3.0/barcode/index.png/recognize?Type=all&ChecksumValidation=Off&DetectEncoding=false&Preset=HighQuality" -H  "accept: application/json" -H  "authorization: Bearer <JWT Token>"

請求網址

https://api.aspose.cloud/v3.0/barcode/index.png/recognize?Type=all&ChecksumValidation=Off&DetectEncoding=false&Preset=HighQuality

從外部圖片網址讀取條碼

// 對於完整的範例和數據文件,請訪問 https://github.com/aspose-barcode-cloud/aspose-barcode-cloud-java/

String type = null;
String checksumValidation = ChecksumValidation.OFF.toString();
Boolean detectEncoding = null;
String preset = PresetType.HIGHPERFORMANCE.toString();
String url = "http://www.barcoding.com/images/Barcodes/pdf417.gif";

Integer rectX = null;
Integer rectY = null;
Integer rectWidth = null;
Integer rectHeight = null;
Boolean stripFNC = null;
Integer timeout = null;
Integer medianSmoothingWindowSize = null;
Boolean allowMedianSmoothing = null;
Boolean allowComplexBackground = null;
Boolean allowDatamatrixIndustrialBarcodes = null;
Boolean allowDecreasedImage = null;
Boolean allowDetectScanGap = null;
Boolean allowIncorrectBarcodes = null;
Boolean allowInvertImage = null;
Boolean allowMicroWhiteSpotsRemoving = null;
Boolean allowOneDFastBarcodesDetector = null;
Boolean allowOneDWipedBarsRestoration = null;
Boolean allowQRMicroQrRestoration = null;
Boolean allowRegularImage = null;
Boolean allowSaltAndPepperFiltering = null;
Boolean allowWhiteSpotsRemoving = null;
Double regionLikelihoodThresholdPercent = null;
List<Integer> scanWindowSizes = null;
Double similarity = null;
Boolean skipDiagonalSearch = null;
String australianPostEncodingTable = null;
String rectangleRegion = null;
File image = null;

BarcodeResponseList response = 
   	 api.postBarcodeRecognizeFromUrlOrContent( 
      		type,checksumValidation,detectEncoding,preset,rectX,rectY,rectWidth,rectHeight,
      		stripFNC,timeout,medianSmoothingWindowSize,allowMedianSmoothing,allowComplexBackground,
      		allowDatamatrixIndustrialBarcodes,allowDecreasedImage,allowDetectScanGap,
		allowIncorrectBarcodes,allowInvertImage,allowMicroWhiteSpotsRemoving,allowOneDFastBarcodesDetector,
      		allowOneDWipedBarsRestoration,allowQRMicroQrRestoration,allowRegularImage,allowSaltAndPepperFiltering,
      		allowWhiteSpotsRemoving,regionLikelihoodThresholdPercent,scanWindowSizes,similarity,skipDiagonalSearch,
      		australianPostEncodingTable,rectangleRegion,url,image);

assertNotNull(response);
assertFalse(response.getBarcodes().isEmpty());

BarcodeResponse barcode = response.getBarcodes().get(0);
assertEquals(DecodeBarcodeType.CODE11.getValue(), barcode.getType());
assertEquals("1234567812", barcode.getBarcodeValue());

結論

在這篇文章中,我們討論了如何使用 Java 程式化地創建條碼的步驟和相關細節,以及如何使用 Java 程式碼片段讀取和識別現有的條碼。您可能已經注意到,所有這些操作都是用幾行簡單的程式碼完成的。無需額外的軟體下載或安裝,這些操作可以用更少的程式碼行來完成。

相關文章

我們建議您訪問以下連結以了解更多資訊