Class BarcodeGenerator
Namespace: Aspose.BarCode.Generation
Assembly: Aspose.BarCode.dll (25.1.0)
BarcodeGenerator สำหรับการสร้างภาพบาร์โค้ดด้านหลัง
รูปแบบที่รองรับ: 1D: Codabar, Code11, Code128, Code39, Code39FullASCII Code93, EAN13, EAN8, Interleaved2of5, MSI, Standard2of5, UPCA, UPCE, ISBN, GS1Code128, Postnet, Planet EAN14, SCC14, SSCC18, ITF14, SingaporePost ... 2D: Aztec, DataMatrix, PDf417, QR code ...
[XmlSerialization(Name = "Aspose.BarCode.Generator")]
public sealed class BarcodeGenerator : IDisposable
การสืบทอด
การใช้งาน
สมาชิกที่สืบทอด
object.GetType(),
object.ToString(),
object.Equals(object?),
object.Equals(object?, object?),
object.ReferenceEquals(object?, object?),
object.GetHashCode()
ตัวอย่าง
ตัวอย่างนี้แสดงวิธีการสร้างและบันทึกภาพบาร์โค้ด
using(var generator = new BarcodeGenerator(EncodeTypes.Code128))
{
generator.CodeText = "123ABC";
generator.Save("code128.png");
}
ตัวสร้าง
BarcodeGenerator(BaseEncodeType)
สร้างอินสแตนซ์ของ BarcodeGenerator
public BarcodeGenerator(BaseEncodeType type)
พารามิเตอร์
type
BaseEncodeType
ประเภทบาร์โค้ด ใช้คลาส Aspose.BarCode.Generation.EncodeTypes เพื่อตั้งค่ารูปแบบบาร์โค้ด
BarcodeGenerator(BaseEncodeType, string)
สร้างอินสแตนซ์ของ BarcodeGenerator
public BarcodeGenerator(BaseEncodeType type, string codeText)
พารามิเตอร์
type
BaseEncodeType
ประเภทบาร์โค้ด ใช้คลาส Aspose.BarCode.Generation.EncodeTypes เพื่อตั้งค่ารูปแบบบาร์โค้ด
codeText
string
ข้อความที่จะเข้ารหัส
คุณสมบัติ
BarcodeType
ประเภทบาร์โค้ด
[XmlSerialization(Type = XmlSerializationType.Element)]
public BaseEncodeType BarcodeType { get; set; }
ค่าของคุณสมบัติ
CodeText
ข้อความที่จะเข้ารหัส
[XmlSerialization(Type = XmlSerializationType.Element)]
public string CodeText { get; set; }
ค่าของคุณสมบัติ
Parameters
พารามิเตอร์การสร้าง
[XmlSerialization(Type = XmlSerializationType.Element)]
public BaseGenerationParameters Parameters { get; }
ค่าของคุณสมบัติ
วิธีการ
Dispose()
public void Dispose()
ExportToXml(string)
ส่งออกคุณสมบัติของ BarCode ไปยังไฟล์ xml ที่ระบุ
public bool ExportToXml(string xmlFile)
พารามิเตอร์
xmlFile
string
ชื่อไฟล์
คืนค่า
ระบุว่าการส่งออกเสร็จสมบูรณ์หรือไม่
คืนค่า True ในกรณีที่สำเร็จ; False มิฉะนั้น
ExportToXml(Stream)
ส่งออกคุณสมบัติของ BarCode ไปยังสตรีม xml ที่ระบุ
public bool ExportToXml(Stream xml)
พารามิเตอร์
xml
Stream
สตรีม xml
คืนค่า
ระบุว่าการส่งออกเสร็จสมบูรณ์หรือไม่
คืนค่า True ในกรณีที่สำเร็จ; False มิฉะนั้น
GenerateBarCodeImage()
สร้างภาพบาร์โค้ดภายใต้การตั้งค่าปัจจุบัน
public Bitmap GenerateBarCodeImage()
คืนค่า
Bitmap
ภาพบาร์โค้ด ดู System.Drawing.Bitmap
ตัวอย่าง
ตัวอย่างนี้แสดงวิธีการสร้างและบันทึกภาพบาร์โค้ด
using(var generator = new BarcodeGenerator(EncodeTypes.Code128))
{
Bitmap barcode = generator.GenerateBarCodeImage();
barcode.Save("test.png");
}
ImportFromXml(string)
นำเข้าคุณสมบัติของ BarCode จากไฟล์ xml ที่ระบุและสร้างอินสแตนซ์ BarcodeGenerator
public static BarcodeGenerator ImportFromXml(string xmlFile)
พารามิเตอร์
xmlFile
string
ชื่อไฟล์
คืนค่า
อินสแตนซ์ BarcodeGenerator
ImportFromXml(Stream)
นำเข้าคุณสมบัติของ BarCode จากสตรีม xml ที่ระบุและสร้างอินสแตนซ์ BarcodeGenerator
public static BarcodeGenerator ImportFromXml(Stream xml)
พารามิเตอร์
xml
Stream
สตรีม xml
คืนค่า
อินสแตนซ์ BarcodeGenerator
Save(Stream, BarCodeImageFormat)
บันทึกภาพบาร์โค้ดลงในสตรีมในรูปแบบเฉพาะ
public void Save(Stream stream, BarCodeImageFormat format)
พารามิเตอร์
stream
Stream
System.IO.Stream ที่ส่งออก
format
BarCodeImageFormat
ระบุรูปแบบไฟล์ของภาพที่ส่งออก
Save(string, BarCodeImageFormat)
บันทึกภาพบาร์โค้ดลงในไฟล์เฉพาะในรูปแบบเฉพาะ
public void Save(string filename, BarCodeImageFormat format)
พารามิเตอร์
filename
string
ที่อยู่ในการบันทึก
format
BarCodeImageFormat
ระบุรูปแบบไฟล์ของภาพที่ส่งออก
Save(string)
บันทึกภาพบาร์โค้ดลงในไฟล์เฉพาะ
public void Save(string filename)
พารามิเตอร์
filename
string
ที่อยู่ในการบันทึก
SetCodeText(byte[])
ตั้งค่า codetext เป็นลำดับของไบต์
public void SetCodeText(byte[] codeBytes)
พารามิเตอร์
codeBytes
byte[]
ไบต์ของ codetext
SetCodeText(string, Encoding)
เข้ารหัส codetext ด้วย byte order mark (BOM) โดยใช้การเข้ารหัสที่กำหนด: เช่น UTF8, UTF16, UTF32 เป็นต้น
บาร์โค้ด 1D ควรใช้ Encoding.ASCII หรือ ISO/IEC 8859-1 - Encoding.GetEncoding(28591)
บาร์โค้ด 2D ควรใช้ Encoding.UTF8
public void SetCodeText(string codeText, Encoding encoding)
พารามิเตอร์
codeText
string
สตริง CodeText
encoding
Encoding
การเข้ารหัสที่ใช้
ตัวอย่าง
ตัวอย่างนี้แสดงวิธีการใช้ SetCodeText กับบาร์โค้ด 1D และ 2D
//เข้ารหัส codetext ของบาร์โค้ด 1D ด้วยการเข้ารหัส ASCII 7-bit ไม่มี byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
gen.SetCodeText("123ABCD", Encoding.ASCII);
gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//เข้ารหัส codetext ของบาร์โค้ด 1D ด้วยการเข้ารหัส ISO/IEC 8859-1 8-bit ไม่มี byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
gen.SetCodeText("123ABCD", Encoding.GetEncoding(28591));
gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//เข้ารหัส codetext ของบาร์โค้ด 2D ด้วยการเข้ารหัส UTF8 พร้อม byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
gen.SetCodeText("123ABCD", Encoding.UTF8);
gen.Save("barcode.png", BarCodeImageFormat.Png);
}
SetCodeText(string, Encoding, bool)
เข้ารหัส codetext โดยการใส่ byte order mark (BOM) ตามที่เลือก โดยใช้การเข้ารหัสที่กำหนด: เช่น UTF8, UTF16, UTF32 เป็นต้น
บาร์โค้ด 1D ควรใช้ Encoding.ASCII หรือ ISO/IEC 8859-1 - Encoding.GetEncoding(28591)
บาร์โค้ด 2D ควรใช้ Encoding.UTF8
public void SetCodeText(string codeText, Encoding encoding, bool insertBOM)
พารามิเตอร์
codeText
string
สตริง CodeText
encoding
Encoding
การเข้ารหัสที่ใช้
insertBOM
bool
ธงที่ระบุการใส่ byte order mark (BOM) ของการเข้ารหัส ในกรณีที่การเข้ารหัสต้องการการใส่ byte order mark (BOM): เช่น UTF8,
UTF16, UTF32 เป็นต้น และธงถูกตั้งค่าเป็นจริง BOM จะถูกเพิ่ม หากตั้งธงเป็นเท็จ การใส่ BOM จะถูกละเว้น
ตัวอย่าง
ตัวอย่างนี้แสดงวิธีการใช้ SetCodeText กับบาร์โค้ด 1D และ 2D
//เข้ารหัส codetext ของบาร์โค้ด 1D ด้วยการเข้ารหัส ASCII 7-bit ไม่มี byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
gen.SetCodeText("123ABCD", Encoding.ASCII, true);
gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//เข้ารหัส codetext ของบาร์โค้ด 1D ด้วยการเข้ารหัส ISO/IEC 8859-1 8-bit ไม่มี byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
gen.SetCodeText("123ABCD", Encoding.GetEncoding(28591), true);
gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//เข้ารหัส codetext ของบาร์โค้ด 2D ด้วยการเข้ารหัส UTF8 พร้อม byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
gen.SetCodeText("123ABCD", Encoding.UTF8, true);
gen.Save("barcode.png", BarCodeImageFormat.Png);
}
//เข้ารหัส codetext ของบาร์โค้ด 2D ด้วยการเข้ารหัส UTF8 โดยไม่ต้องมี byte order mark (BOM)
using (BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.Code128))
{
gen.SetCodeText("123ABCD", Encoding.UTF8, false);
gen.Save("barcode.png", BarCodeImageFormat.Png);
}