บทช่วยสอนทีละขั้นตอนนี้แสดงวิธีการหมุนภาพบาร์โค้ดใน C# มันหมุนบาร์โค้ดที่สร้างขึ้นตามมุมที่กำหนดในโค้ด C# บาร์โค้ดสามารถหมุนในแนวนอนหรือแนวตั้งได้ตามความต้องการของคุณในแอปพลิเคชัน C#
ขั้นตอนในการหมุนภาพบาร์โค้ดใน C#
- รวม Aspose.BarCode for .NET แพ็คเกจ Nuget
- เพิ่มการอ้างอิงถึงเนมสเปซ Aspose.Barcode และ Aspose.BarCode.Generation
- ใช้วิธี SetLicense เพื่อใช้ใบอนุญาต
- สร้างวัตถุของ BarCodeGenerator Class โดยใช้ EncodeType เป็น Code128
- ระบุข้อความบาร์โค้ดโดยใช้คุณสมบัติ CodeText
- กำหนดมุมการหมุนที่ต้องการโดยใช้แอตทริบิวต์ RotationAngle
- บันทึกภาพบาร์โค้ดที่หมุนเป็นรูปแบบภาพ PNG
ในบทช่วยสอนอื่น เราได้แสดงรหัสสำหรับ สร้างรหัส QR ใน C # ตั้งแต่เริ่มต้น บาร์โค้ดนั้นไม่มีการหมุน อย่างไรก็ตาม เมื่อทำตามขั้นตอนข้างต้น คุณจะสามารถสร้างบาร์โค้ดแบบหมุนใน C# ได้เช่นกัน
รหัสเพื่อหมุนภาพบาร์โค้ดใน C
using System; | |
//Use following namespaces to rotate barcode image | |
using Aspose.BarCode; | |
using Aspose.BarCode.Generation; | |
namespace RotateBarCodeImage | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//Set license before rotating barcode image | |
Aspose.BarCode.License AsposeBarCodeLicense = new Aspose.BarCode.License(); | |
AsposeBarCodeLicense.SetLicense(@"c:\asposelicense\license.lic"); | |
//initiate barcode generator object with Code128 encode type | |
BarcodeGenerator RotateBarCodeImage = new BarcodeGenerator(EncodeTypes.Code128); | |
RotateBarCodeImage.CodeText = "Product Code 123"; | |
//set rotation of the barcode | |
RotateBarCodeImage.Parameters.RotationAngle = 45; | |
//save rotated barcode image as PNG | |
RotateBarCodeImage.Save("Rotated_BarCode_Image.png", BarCodeImageFormat.Png); | |
} | |
} | |
} |
ในตัวอย่างข้างต้น เราได้หมุนบาร์โค้ดที่ 45 องศา แต่คุณสามารถหมุนบาร์โค้ดที่สร้างขึ้นที่องศาใดก็ได้ ตัวอย่างเช่น คุณอาจต้องการหมุนบาร์โค้ดที่ 90 องศาในเว็บแอปพลิเคชัน C# หรือเดสก์ท็อป