Search code examples
c#barcodezxing

ZXing.NET "No encoder available for format" exception


I'm using ZXing.net to support supplying barcode encoding of values from a web service. I have the following function which works great when used with most of the recognized encoding formats as found in the BarcodeFormat enum. However, seven of the codes (ALL_1D, IMB, MAXICODE, MSI, RSS_14, RSS_EXPANDED, UPC_EAN_EXTENSION) result in a "No encoder available for format" exception.

Is this an expected result; i.e., are these formats not yet supported? Just seems they would not be recognized (not found in the enum) if they were not yet implemented.

public static Bitmap EncodeValueBarcode(string text, BarcodeFormat format, int height)
{
    Bitmap bmp = null;

    var writer = new BarcodeWriter
    {
        Format = format,
        Options = new ZXing.Common.EncodingOptions()
    };
    if (height > 0)
        writer.Options.Height = height;
    if (width > 0)
        writer.Options.Width = width;

    bmp = writer.Write(text);

    return bmp;
}

Solution

  • The enumeration BarcodeFormat is used for encoding and decoding. It contains every format which is at least supported by one of the both. The error which you get means what it says: there is no encoder support for that particular format. Not every format which can be decoded has an implemented encoder.