1

Closed

Datamatrix in WPF: decoded value is different from encoded

description

Datamatrix encoding algorithm seems to work incorrectly at some input values.

For example input string value:
"10112z054********************10***200***2032*301"
is encoded as
"10112z054********************10***200***2032*304 41>W"
regardless of whether the barcode is generated using BarcodeWriter or BarcodeWriterGeometry.

I decoded Datamatrix by:
bcTester (Windows version, http://www.bctester.de/en/home.html)
NeoReader(Android version, http://www.neoreader.com/)

Code behind:
void _txtValueToEncode_TextChanged(object sender, TextChangedEventArgs e)
{
    var pathWriter = new ZXing.Presentation.BarcodeWriterGeometry
    {
        Format = ZXing.BarcodeFormat.DATA_MATRIX
        //Options = new EncodingOptions
        //{
        //    Height = 100,
        //    Width = 100,
        //    Margin = 0
        //}
    };

    _barcodePath.Data = pathWriter.Write(_txtValueToEncode.Text);


    var writer = new ZXing.Presentation.BarcodeWriter
    {
        Format = ZXing.BarcodeFormat.DATA_MATRIX
        //Options = new EncodingOptions
        //{
        //    Height = 100,
        //    Width = 100,
        //    Margin = 0
        //}
    };

    _barcodeImage.Source = writer.Write(_txtValueToEncode.Text);
}
XAML:
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Path Grid.Column="0" Name="_barcodePath" Stretch="Uniform" Margin="30" Fill="Black" />
    <Image Grid.Column="1" Name="_barcodeImage" Stretch="Uniform" Margin="30" />
    <TextBox Grid.Row="1" Height="20" HorizontalAlignment="Stretch" Margin="10,0,10,10" Name="_txtValueToEncode" TextChanged="_txtValueToEncode_TextChanged" Grid.ColumnSpan="2" />
</Grid>
There is no matter whether EncodingOptions are assigned (statically or dynamically or what values they have) or not.
I also noticed that values shorter than 48 characters seem to be encoded correctly.
Value "10112z054********************10***200***2032*304 41>W" (result of the above-mentioned decoding) substituted as input string is then encoded correctly.
Closed Nov 20, 2016 at 6:47 PM by micjahn

comments

micjahn wrote Nov 20, 2016 at 6:47 PM

Fix in next release.
If you want to try it out now you have to build your own ZXing.Net assemblies from source code.

wrote Nov 20, 2016 at 6:47 PM