Распознавание и генерация штрих-кодов QR Code используя VintaSoft Barcode .NET SDK
Категория: Штрих-коды; .NET
24 июня 2025
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
/// <summary>
/// Reads QR Code barcodes from a <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="bitmap">A bitmap with barcodes.</param>
public static void ReadQRCodeBarcodesFromBitmap(System.Drawing.Bitmap bitmap)
{
// create barcode reader
using (Vintasoft.Barcode.BarcodeReader reader = new Vintasoft.Barcode.BarcodeReader())
{
// specify that reader must search for QR Code barcodes
reader.Settings.ScanBarcodeTypes = Vintasoft.Barcode.BarcodeType.QR;
// read barcodes from image
Vintasoft.Barcode.IBarcodeInfo[] infos = Vintasoft.Barcode.GdiExtensions.ReadBarcodes(reader, bitmap);
// if barcodes are not detected
if (infos.Length == 0)
{
System.Console.WriteLine("No barcodes found.");
}
// if barcodes are detected
else
{
// get information about extracted barcodes
System.Console.WriteLine(string.Format("{0} barcodes found:", infos.Length));
System.Console.WriteLine();
for (int i = 0; i < infos.Length; i++)
{
Vintasoft.Barcode.IBarcodeInfo info = infos[i];
System.Console.WriteLine(string.Format("[{0}:{1}]", i + 1, info.BarcodeType));
System.Console.WriteLine(string.Format("Value: {0}", info.Value));
System.Console.WriteLine(string.Format("Region: {0}", info.Region));
System.Console.WriteLine();
}
}
}
}
/// <summary>
/// Returns the QR Code barcode as <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="value">The barcode value.</param>
/// <returns>A <see cref="System.Drawing.Bitmap"/> object.</returns>
public static System.Drawing.Bitmap GetQRCodeBarcodeAsBitmap(string value)
{
// create the barcode writer
using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
{
// set barcode writer settings
barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.QR;
barcodeWriter.Settings.Value = value;
// get a barcode image as System.Drawing.Bitmap
return Vintasoft.Barcode.GdiExtensions.GetBarcodeAsBitmap(barcodeWriter);
}
}
/// <summary>
/// Returns the Micro QR barcode as <see cref="System.Drawing.Bitmap"/>.
/// </summary>
/// <param name="value">The barcode value.</param>
/// <returns>A <see cref="System.Drawing.Bitmap"/> object.</returns>
public static System.Drawing.Bitmap GetMicroQRBarcodeAsBitmap(string value)
{
// create the barcode writer
using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
{
// set barcode writer settings
barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.MicroQR;
barcodeWriter.Settings.Value = value;
// get a barcode image as System.Drawing.Bitmap
return Vintasoft.Barcode.GdiExtensions.GetBarcodeAsBitmap(barcodeWriter);
}
}
/// <summary>
/// Returns the QR Code barcode in vector form as a SVG string.
/// </summary>
/// <param name="barcodeValue">Barcode value.</param>
public static void GetQrCodeBarcodeAsSvgString(string barcodeValue)
{
// create the barcode writer
using (Vintasoft.Barcode.BarcodeWriter barcodeWriter = new Vintasoft.Barcode.BarcodeWriter())
{
// set barcode writer settings
barcodeWriter.Settings.Barcode = Vintasoft.Barcode.BarcodeType.QR;
barcodeWriter.Settings.Value = barcodeValue;
// generate QR Code barcode as a SVG string
return barcodeWriter.GetBarcodeAsSvgFile();
}
}