VintaSoft Barcode .NET SDK 16.0: Руководство для .NET разработчика
Vintasoft.Barcode.BarcodeInfo Namespace / EciCharacterEncoder Class
Класс EciCharacterEncoder
В этом разделе
Предоставляет методы кодирования символов расширенной интерпретации канала (ECI).
Объектная модель
EciCharacterEncoder
Синтаксис
'Declaration

Public Class EciCharacterEncoder

public class EciCharacterEncoder

Ремарки

Символ ECI в значении штрих-кода определяет кодировку текста после символа ECI и до конца значения штрих-кода или следующего символа ECI.
Для хранения текста можно использовать несколько символов ECI с разными значениями. кодировки символов в одном значении штрих-кода.

Важно! Не все распознавантели штрих-кодов поддерживают символы ECI! Используйте символы ECI, только если ваш распознаватель штрих-кодов поддерживает символы ECI. Используйте текст в кодировке UTF8 и кодируйте текст как байты (System.Text.Encoding.GetBytes(System.String)), если вы не уверены в поддержке символов ECI вашим распознавателем штрих-кода.

ECI символы доступны только для штрих-кодов Aztec, DataMatrix, QR, Han Xin Code, PDF417 или Micro PDF417.

Пример

Вот C#/VB.NET код, который демонстрирует, как закодировать и декодировать текст с использованием различных текстовых кодировок:

   
Imports System.Text   
   
Imports Vintasoft.Barcode   
Imports Vintasoft.Barcode.BarcodeInfo   
Imports Vintasoft.Imaging   
   
''' <summary>
''' Class that shows how to create an image with barcode Aztec, DataMatrix, QR, PDF417
''' or Micro PDF417, which stores text in different encodings.
''' Barcode value is encoded using the EciCharacterEncoder class.
''' </summary>
Class EciCharacterEncoderExample   
    ''' <summary>
    ''' Runs the test.
    ''' </summary>
    Public Shared Sub Run()   
        ' ECI characters are available only for Aztec, DataMatrix, DotCode, QR, Han Xin Code, PDF417 or Micro PDF417 barcodes
        Dim barcode As BarcodeType = BarcodeType.DataMatrix   
   
        ' create the encoder of Extended Channel Interpretation (ECI) characters
        Dim eciEncoder As New EciCharacterEncoder(barcode)   
   
        ' create the ECI encoding for encoding text in codepage 28592
        Dim cp28592EciEncoding As EciCharacterEncoding = EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(28592))   
        ' append text in codepage 28592 to ECI encoder
        eciEncoder.AppendText(cp28592EciEncoding, "azszecnolAZSZECNOL")   
   
        ' create the ECI encoding for encoding text in codepage 28595
        Dim cp28595EciEncoding As EciCharacterEncoding = EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(28595))   
        ' append text in codepage 28595 to ECI encoder
        eciEncoder.AppendText(cp28595EciEncoding, "����������������")   
   
        ' create the ECI encoding for encoding text in codepage 950
        Dim cp950EciEncoding As EciCharacterEncoding = EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(950))   
        ' append text in codepage 950 to ECI encoder
        eciEncoder.AppendText(cp950EciEncoding, "???????")   
   
        ' create the ECI encoding for encoding text in codepage 28591
        Dim cp28591EciEncoding As EciCharacterEncoding = EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(28591))   
        ' append text in codepage 28591 to ECI encoder
        eciEncoder.AppendText(cp28591EciEncoding, "test!")   
   
   
        ' create the barcode writer
        Using writer As New BarcodeWriter()   
            ' specify that writer must generate barcode of specified type
            writer.Settings.Barcode = barcode   
   
            ' set the barcode value as value encoded by ECI encoder
            writer.Settings.ValueItems = eciEncoder.ToValueItems()   
   
            ' create image with barcode
            Using barcodeImage As VintasoftBitmap = writer.GetBarcodeAsVintasoftBitmap()   
                ' create the barcode reader
                Using reader As New BarcodeReader()   
                    ' specify that reader must search for barcodes of specified type
                    reader.Settings.ScanBarcodeTypes = barcode   
   
                    ' read barcode from image
                    Dim decodeItems As ValueItemBase() = reader.ReadBarcodes(barcodeImage)(0).ValueItems   
   
                    ' decode the barcode value
                    Dim decodedString As String = EciCharacterDecoder.Decode(decodeItems)   
   
                    ' if decoded value does not match source value
                    If decodedString <> "azszecnolAZSZECNOL����������������???????test!" Then   
                        ' throw exception
                        Throw New ApplicationException()   
                    End If   
                End Using   
            End Using   
        End Using   
   
        Console.WriteLine("OK")   
    End Sub   
End Class


using System;
using System.Text;

using Vintasoft.Barcode;
using Vintasoft.Barcode.BarcodeInfo;
using Vintasoft.Imaging;

/// <summary>
/// Class that shows how to create an image with barcode Aztec, DataMatrix, QR, PDF417
/// or Micro PDF417, which stores text in different encodings.
/// Barcode value is encoded using the EciCharacterEncoder class.
/// </summary>
class EciCharacterEncoderExample
{
    /// <summary>
    /// Runs the test.
    /// </summary>
    public static void Run()
    {
        // ECI characters are available only for Aztec, DataMatrix, DotCode, QR, Han Xin Code, PDF417 or Micro PDF417 barcodes
        BarcodeType barcode = BarcodeType.DataMatrix;

        // create the encoder of Extended Channel Interpretation (ECI) characters
        EciCharacterEncoder eciEncoder = new EciCharacterEncoder(barcode);

        // create the ECI encoding for encoding text in codepage 28592
        EciCharacterEncoding cp28592EciEncoding =
            EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(28592));
        // append text in codepage 28592 to ECI encoder
        eciEncoder.AppendText(cp28592EciEncoding, "ążśźęćńółĄŻŚŹĘĆŃÓŁ");

        // create the ECI encoding for encoding text in codepage 28595
        EciCharacterEncoding cp28595EciEncoding =
            EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(28595));
        // append text in codepage 28595 to ECI encoder
        eciEncoder.AppendText(cp28595EciEncoding, "АБВГДЕЖЗИЙКЛМНОП");

        // create the ECI encoding for encoding text in codepage 950
        EciCharacterEncoding cp950EciEncoding =
            EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(950));
        // append text in codepage 950 to ECI encoder
        eciEncoder.AppendText(cp950EciEncoding, "日月火水木金土");

        // create the ECI encoding for encoding text in codepage 28591
        EciCharacterEncoding cp28591EciEncoding =
            EciCharacterEncoding.GetEciCharacterEncodingForEncoding(Encoding.GetEncoding(28591));
        // append text in codepage 28591 to ECI encoder
        eciEncoder.AppendText(cp28591EciEncoding, "test!");


        // create the barcode writer
        using (BarcodeWriter writer = new BarcodeWriter())
        {
            // specify that writer must generate barcode of specified type
            writer.Settings.Barcode = barcode;

            // set the barcode value as value encoded by ECI encoder
            writer.Settings.ValueItems = eciEncoder.ToValueItems();

            // create image with barcode
            using (VintasoftBitmap barcodeImage = writer.GetBarcodeAsVintasoftBitmap())
            {
                // create the barcode reader
                using (BarcodeReader reader = new BarcodeReader())
                {
                    // specify that reader must search for barcodes of specified type
                    reader.Settings.ScanBarcodeTypes = barcode;

                    // read barcode from image
                    ValueItemBase[] decodeItems = reader.ReadBarcodes(barcodeImage)[0].ValueItems;

                    // decode the barcode value
                    string decodedString = EciCharacterDecoder.Decode(decodeItems);

                    // if decoded value does not match source value
                    if (decodedString != "ążśźęćńółĄŻŚŹĘĆŃÓŁАБВГДЕЖЗИЙКЛМНОП日月火水木金土test!")
                        // throw exception
                        throw new ApplicationException();
                }
            }
        }

        Console.WriteLine("OK");
    }
}

Иерархия наследования

System.Object
   Vintasoft.Barcode.BarcodeInfo.EciCharacterEncoder

Требования

Целевые платформы: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

Смотрите также