Aspose.BarCode เป็นห้องสมุดที่มีประสิทธิภาพที่ง่ายต่อการสร้างรหัสบาร์การรับรู้และการจัดการในสภาพแวดล้อมการเขียนต่างๆ บทความนี้มุ่งเน้นไปที่การใช้ส่วนประกอบ 1D Barcode Writer ของ Asposa. BarCodes ในสภาพภูมิอากาศ .NET ไม่ว่าคุณกําลังพัฒนาแอพพลิเคชันที่จําเป็นต้องมีร่องรัดหรือปรับปรุงที่มีอยู่ด้วยฟังก์ชั่นนี้คู่มือนี้จะช่วยให้คุณผ่านการตั้งค่าสภาพผนังการพัฒนาของคุณ generating barcodes, and best practices for working with ASPOSE.
การติดตั้ง
ก่อนที่จะไปสู่การสร้างบาร์โค้ดให้แน่ใจว่าส่วนประกอบที่จําเป็นจะถูกติดตั้งในโครงการ .NET ของคุณ วิธีที่ง่ายที่สุดในการรวม Aspose.BarCode คือผ่าน NuGet Package Manager ซึ่งช่วยให้การติดตั้งแบบไร้สายของห้องสมุดและความสัมพันธ์ของมัน.
- Open Visual Studio หรือ IDE ที่ต้องการใด ๆ.
- คลิกขวาบนโครงการของคุณใน Solution Explorer และเลือก “จัดการแพคเกจ NuGet”.
- ค้นหา
Aspose.BarCode
ในผู้จัดการแพคเกจและติดตั้ง.
ตัวเลือกคุณสามารถใช้คําสั่งต่อไปนี้ในคอนโซลผู้จัดการแพคเกจ:
using System;
using System.IO;
using Aspose.BarCode;
namespace BarcodeExample
{
class Program
{
static void Main(string[] args)
{
// Set license for Aspose.BarCode
SetLicense();
// Generate a basic barcode and save it to the file system
GenerateBasicBarcode();
// Generate a custom barcode with specific settings and save it to the file system
GenerateCustomBarcode();
// Generate a barcode using BarcodeWriter approach and save it to the file system
GenerateUsingBarcodeWriter();
}
/// <summary>
/// Sets the license for Aspose.BarCode.
/// </summary>
public static void SetLicense()
{
try
{
// set metered public and private keys
Aspose.BarCode.Metered metered = new Aspose.BarCode.Metered();
// Access the setMeteredKey property and pass the public and private keys as parameters
metered.SetMeteredKey("*****", "*****");
Console.WriteLine("License set successfully.");
}
catch (Exception ex)
{
Console.WriteLine($"Error setting license: {ex.Message}");
}
}
/// <summary>
/// Generates a basic barcode and saves it to the file system.
/// </summary>
public static void GenerateBasicBarcode()
{
// Create an instance of BarcodeGenerator and set its properties
using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample Text"))
{
// Save barcode image to file system
generator.Save("barcode.png", BarCodeImageFormat.Png);
Console.WriteLine("Basic barcode generated successfully.");
}
}
/// <summary>
/// Generates a custom barcode with specific settings and saves it to the file system.
/// </summary>
public static void GenerateCustomBarcode()
{
// Create an instance of BarcodeGenerator
using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128))
{
// Set the barcode data
generator.CodeText = "Sample Text";
// Customize symbology settings
generator.Parameters.SymbologyParameters.Code128.AutoExcludeCodabar = true;
// Save barcode image to file system with custom format and size
generator.Save("custom_barcode.png", BarCodeImageFormat.Png, 400, 200);
Console.WriteLine("Custom barcode generated successfully.");
}
}
/// <summary>
/// Generates a barcode using the BarcodeWriter approach and saves it to the file system.
/// </summary>
public static void GenerateUsingBarcodeWriter()
{
// Create an instance of BarcodeGenerator
using (BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "Sample Text"))
{
// Get barcode image as a stream
using (MemoryStream ms = new MemoryStream())
{
generator.Save(ms, BarCodeImageFormat.Png);
// Write the content of memory stream to file system
File.WriteAllBytes("barcode_writer.png", ms.ToArray());
Console.WriteLine("Barcode generated using BarcodeWriter approach successfully.");
}
}
}
}
}
เมื่อติดตั้งแล้วคุณพร้อมที่จะเริ่มสร้างรหัสบาร์โดยใช้คลาส BarcodeWriter ของ Aspose.BarCode.
สร้างใบอนุญาต
เพื่อให้แน่ใจว่ามีฟังก์ชั่นเต็มรูปแบบและการสนับสนุนสําหรับการใช้งานเชิงพาณิชย์จึงเป็นสิ่งสําคัญที่จะสร้างไฟล์ใบอนุญาต ขั้นตอนนี้จะปลดล็อคคุณสมบัติทั้งหมดของห้องสมุดและลบข้อ จํากัดใด ๆ ที่มาพร้อมกับรุ่นทดลอง.
- รับคีย์ใบอนุญาตของคุณจากเว็บไซต์ Aspose หลังจากซื้อหรือลงทะเบียนสําหรับการทดสอบฟร.
- สร้างตัวอย่างของ
Metered
คลาสและเรียกมันSetMeteredKey()
วิธีการผ่านในคีย์ใบอนุญาตที่ได้รับผ่านทางอีเมล:
สร้างบาร์โค้ด
ด้วย Aspose.BarCode การ generating barcodes เป็นเรื่องง่ายและสามารถปรับแต่งได้ตามความต้องการของคุณ นี่คือวิธีที่คุณสามารถสร้าง barcode ฐาน:
ฐาน Barcode Generation
เพื่อสร้างรหัสบาร์ที่เรียบง่ายใช BarcodeGenerator
ประเภทของ The Aspose.BarCode.Generation
หมายเลข.
การปรับแต่งรหัสบาร
Aspose.BarCode ช่วยให้การกําหนดเองของรหัสบาร์อย่างกว้างขวาง คุณสามารถปรับการตั้งค่าสัญลักษณ์ตัวเลือกข้อความและคุณสมบัติการปรากฏ.
บาร์โค้ดคลาส
อะไร BarcodeGenerator
คลาสเป็นเครื่องมือหลักสําหรับการสร้างรหัสบาร์ใน Aspose.BarCode อย่างไรก็ตามถ้าคุณต้องการการควบคุมการผลิตและ rendering รหัส Barcode มองไปใช BarcodeWriter
หลักสูตร.
แนวทางที่ดีที่สุด
เมื่อทํางานกับ Aspose.BarCode ในแอพ .NET ของคุณพิจารณาการปฏิบัติที่ดีที่สุดเหล่าน:
การจัดการข้อผิดพลาด: รวมถึงกลไกการแก้ปัญหาเมื่อสร้างใบอนุญาตและสร้างรหัสบาร์ ซึ่งช่วยให้แน่ใจว่าปัญหาใด ๆ จะถูกจับได้ก่อนหน้านี้และสามารถแก้ไขได้ทันท.
**การปรับปรุงประสิทธิภาพ: ** สําหรับสถาปัตยกรรมที่มีประสิทธิภาพสูงเพิ่มประสิทธิภาพการผลิตรหัสบาร์โดยการลดปริมาณการโทร
Save()
หรือวิธีการที่คล้ายกัน โปรดพิจารณาการประมวลผลแพทช์ถ้าคุณต้องการสร้างรหัสบาร์หลายครั้ง.ความปลอดภัย: ให้แน่ใจว่าไฟล์ใบอนุญาตของคุณจะถูกบันทึกได้อย่างปลอดภัยและไม่สามารถเข้าถึงได้ผ่านทางสาธารณะ สิ่งนี้ป้องกันไม่ให้การใช้งานที่ไม่ได้รับอนุญาโตตุลาการของคุณ.
ข้อสรุป
Aspose.BarCode simplifies the process of generating, recognising, and manipulating barcodes in .NET applications. By following this guide, you can efficiently integrate barcode functionality into your projects with minimal effort. สําหรับข้อมูลรายละเอียดเพิ่มเติมหรือคุณสมบัติขั้นสูง, ไปยังเอกสารอย่างเป็นทางการที่มีอยู่ใน https://kb.aspose.net/barcode/1d-barcode-writer/.
ด้วย API ที่แข็งแกร่งของ Aspose.BarCode และตัวเลือกการปรับแต่งที่กว้างขวางคุณสามารถสร้างรหัสบาร์ที่มีคุณภาพสูงเพื่อตอบสนองความต้องการเฉพาะของคุณ.