This project has moved and is read-only. For the latest updates, please go here.

Size issue in a WPF app

Jul 11, 2014 at 3:39 PM

I try to display a qrcode in WPF but I have sizing issues.
I set the size to 100/100 but 2 generated qrcode from two different text have not the same sizes. The generated qrcode have sometime a left and top margin and I don't know why.

Here is the code:
 var writer = new BarcodeWriterGeometry
                Format = BarcodeFormat.QR_CODE,
                Options = new ZXing.QrCode.QrCodeEncodingOptions
                    Width = 100,
                    Height = 100,
                    Margin = 0,
            var image = writer.Write(text);
            this._image.Data = image;
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                        <Path x:Name="PART_Image"
                              Fill="{TemplateBinding Foreground}"
                              VerticalAlignment="Center" HorizontalAlignment="Center" />
This is the result :

What's wrong?

Jul 11, 2014 at 8:07 PM
The encoder tries to fit your requested size as good as possible without anti-aliasing.
It scales the image only by an integer factor. So if there is not enough data to fill out the requested size
the unused pixels are white. In such cases it is sometimes better to generate the image with a requested
size of 1x1 and after that you should scale the image manually.
Jul 12, 2014 at 9:11 AM
I'm not generating an image but a Path. Is is working the same way?

I tried before to generate a 1x1 image and scale it but the result was horrible.
Jul 22, 2014 at 9:22 PM
I tried it with a modified version of the WPF demo from the repository.
That's how the writer is called:
                  var writer = new BarcodeWriterGeometry
                        Format = (BarcodeFormat) cmbEncoderType.SelectedItem,
                        Options = new ZXing.Common.EncodingOptions
                              Height = 1, //(int) imageBarcodeEncoder.Height,
                              Width = 1, //(int) imageBarcodeEncoder.Width,
                              Margin = 0
                  var image = writer.Write(txtBarcodeContentEncode.Text);
                  imageBarcodeEncoderGeometry.Data = image;
                  imageBarcodeEncoderGeometry.Visibility = Visibility.Visible;
And I put a Viewbox around the Path:
<Viewbox Stretch="Uniform" Width="200" Height="200" HorizontalAlignment="Left">
   <Path Name="imageBarcodeEncoderGeometry" Fill="Black"/>
In my opinion the result looks very well.