Search code examples
c#.netzxingzxing.net

How can we generate/encode barcode image without border using zxing library in .net code?


How to generate barcode image without border using zxing library.So how to generate it without the border property in .net code?


Solution

  • The following snippet shows a way to generate an image without a border:

                var writer = new ZXing.BarcodeWriter
                {
                    Format = ZXing.BarcodeFormat.QR_CODE,
                    Options = new ZXing.Common.EncodingOptions
                    {
                        Height = 0,
                        Width = 0,
                        Margin = 0
                    },
                };
                var barcodeImage = writer.Write("<your content here>");
    

    But you have to scale the image manually. ZXing.Net only supports scaling without anti-aliasing, so it can't stretch it to a given height and width without border if the scaling factor isn't an integer.

    But you should be careful with barcode images without borders. For example, the QR specification defines a quiet zone (white border) with a size of four modules. If there is no quiet zone it could happen that not every reader can decode it.