この記事では、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
- Pharmacode
- 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>"
リクエストURL
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);

画像 1:- Java API を使用して生成されたバーコードのプレビュー
ラスター画像からバーコードを認識する
APIは、ラスタ画像ファイルからバーコードを認識する機能も提供しています。画像ファイルは、PNG、JPEG、BMP、GIF、TIFF、またはEXIF形式である必要があります。APIの GetBarcodeRecognize メソッドは、この要件を達成することを可能にします。nameフィールドは必須であり、他のオプションフィールドはバーコードタイプ情報、チェックサム検証、エンコーディング、認識品質と速度を設定するためのプリセットなど、より良い認識操作を行うための機能を提供します。
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>"
リクエストURL
https://api.aspose.cloud/v3.0/barcode/index.png/recognize?Type=all&ChecksumValidation=Off&DetectEncoding=false&Preset=HighQuality
外部画像URLからバーコードを読み取る
// 完全な例とデータファイルについては、 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コードスニペットを使用して既存のバーコードを読み取って認識する方法についての手順と関連する詳細を説明しました。これらの操作は、いくつかのシンプルなコード行で実行されることに気づいたかもしれません。追加のソフトウェアのダウンロードやインストールは不要で、これらの操作は少ないコード行で達成できます。
関連する記事
以下のリンクを訪れて、さらに詳しく学ぶことをお勧めします。