ในบทความนี้ เราจะพูดคุยเกี่ยวกับรายละเอียดเกี่ยวกับวิธีการสร้าง Barcode โดยใช้ Java รวมถึงการรู้จำ Barcode โดยใช้ Java API เดียวกัน เราคุ้นเคยกันดีว่า barcode เป็นป้ายระบุหรือฉลากที่แนบอยู่กับสินค้าทั้งหมด ซึ่งช่วยให้คอมพิวเตอร์สามารถติดตามและคิดราคาได้รวดเร็วยิ่งขึ้นและแม่นยำมากขึ้น โดยเฉพาะอย่างยิ่ง พวกมันสามารถพิมพ์ได้ง่ายและเพิ่มลงบนรายการสินค้าได้อย่างทันท่วงที เพื่อให้สินค้าคงคลังทั้งหมดของคุณมีป้ายกำกับและติดตามได้ในทันที นอกจากนี้ Barcode ยังเสนอการระบุผลิตภัณฑ์อัตโนมัติ การรู้จำที่รวดเร็วมาก และการใช้งานข้อมูลที่มีอัตราความผิดพลาดต่ำมาก แนวทางนี้มีความคุ้มค่าทางเศ

API การสร้างบาร์โค้ด

Aspose.BarCode Cloud เป็น REST API ที่ช่วยให้ลูกค้าของเราสามารถนำเสนอการสร้างและการจัดการบาร์โค้ดในโปรแกรมได้

API สามารถ解析รูปแบบภาพแรสเตอร์ยอดนิยมได้ สำหรับรายละเอียดเพิ่มเติม กรุณาเยี่ยมชม Supported File Formats.

สร้างบาร์โค้ดตามขนาดที่กำหนด

วิธีที่รวดเร็วและง่ายที่สุดในการทดสอบ APIs ของเราคือการใช้ส่วนเอกสารอ้างอิง API เมธอด GetBarcodeGenerate ถูกใช้เพื่อสร้างภาพ BarCode และมันมีตัวเลือกมากมายในการสร้าง BarCode ตามความต้องการของคุณและรายละเอียดที่เกี่ยวข้องกับพารามิเตอร์เฉพาะจะมีการอธิบายอย่างชัดเจนในหน้าเอกสารอ้างอิง API ในขณะ generating BarCode คุณสามารถระบุประเภทใดประเภทหนึ่งจากต่อไปนี้

  • 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 command

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>"

Request 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

โค้ดส่วนนี้สามารถใช้เพื่อสร้างภาพ BarCode และเก็บไว้ที่ Cloud Storage ได้

// สำหรับตัวอย่างและไฟล์ข้อมูลทั้งหมด กรุณาไปที่ 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);
BarCode Image

Image 1:- ตัวอย่างของบาร์โค้ดที่สร้างขึ้นด้วย Java API

รับรู้บาร์โค้ดจากภาพแรสเตอร์

API ยังมีความสามารถในการรับรู้ BarCode จากไฟล์รูปภาพแบบแรสเตอร์ ไฟล์รูปภาพสามารถเป็นรูปแบบ PNG, JPEG, BMP, GIF, TIFF หรือ EXIF ได้ วิธีการ GetBarcodeRecognize ของ API ช่วยให้คุณสามารถทำตามความต้องการนี้ได้ ฟิลด์ชื่อเป็นสิ่งจำเป็นและฟิลด์อื่น ๆ ที่เป็นทางเลือกช่วยให้มีความสามารถในการดำเนินการตรวจจับที่ดีกว่า เพราะคุณสามารถระบุข้อมูลประเภท BarCode, ChecksumValidation, Encoding, การตั้งค่าเพื่อตั้งค่าคุณภาพการรับรู้และความเร็ว และอื่น ๆ อีกมากมาย

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>"

Request 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());

ข้อสรุป

ในบทความนี้ เราได้พูดคุยเกี่ยวกับขั้นตอนและรายละเอียดที่เกี่ยวข้องเกี่ยวกับวิธีการสร้าง BarCode อย่างมีโปรแกรมด้วย Java รวมถึงวิธีการอ่านและจดจำ BarCode ที่มีอยู่แล้วโดยใช้โค้ดตัวอย่าง Java คุณอาจสังเกตเห็นว่าการดำเนินการทั้งหมดนี้ทำได้ด้วยบรรทัดโค้ดที่ง่ายเพียงไม่กี่บรรทัด ไม่จำเป็นต้องดาวน์โหลดหรือติดตั้งซอฟต์แวร์เพิ่มเติม และการดำเนินการเหล่านี้สามารถทำได้ด้วยบรรทัดโค้ดที่น้อยลง

บทความที่เกี่ยวข้อง

เราขอแนะนำให้คุณเยี่ยมชมลิงก์ต่อไปนี้เพื่อเรียนรู้เพิ่มเติมเกี่ยวกับ