How to purge padding space between the image border and QRCode symbol?

2 posts, 0 answers
  1. kzimny
    kzimny avatar
    7 posts
    Member since:
    Jul 2007

    Posted 09 Sep Link to this post

    Dear All,

    I have the following code to generate QR Code dynamically:

    public Image GetQRCode(string sUrl, int iDotSize)
    {
        var code = new RadBarcode();
        code.Text = sUrl;
        code.Type = BarcodeType.QRCode;
        code.OutputType = BarcodeOutputType.EmbeddedPNG;
        code.QRCodeSettings.Mode = Telerik.Web.UI.Barcode.Modes.CodeMode.Byte;
        code.QRCodeSettings.ErrorCorrectionLevel = Telerik.Web.UI.Barcode.Modes.ErrorCorrectionLevel.L;
        code.QRCodeSettings.DotSize = iDotSize;
        code.QRCodeSettings.Version = 2;
        code.QRCodeSettings.ECI = Telerik.Web.UI.Barcode.Modes.ECIMode.None;
     
        //code.QRCodeSettings.DotSize = 0; // no changes, space is always there
        //code.Attributes.Add("Width", "310px"); // no changes, space is always there
        //code.Attributes.Add("Height", "310px"); // no changes, space is always there
        return code.GetImage();
    }


    Can any one tell me how to purge padding space between the image border and QRCode symbol?
    According to the documentation changing DotSize to zero should resize the QR symbol to fill up the Width and Height.
    It doesn't work, the white space is always there. I tried also several other setting without success.
    Greatly appreciate for any helps.


    Regards,
    Christopher
  2. kzimny
    kzimny avatar
    7 posts
    Member since:
    Jul 2007

    Posted 13 Sep in reply to kzimny Link to this post

    The margin for the QR code is set by specification and it case it is customized it can lead to illegal QR code that can not be read by the devices. See the specification

     

    public Image GetQRCode(string sUrl, int iDotSize)
    {
        var code = new RadBarcode();
        code.Text = sUrl;
        code.Type = BarcodeType.QRCode;
        code.OutputType = BarcodeOutputType.EmbeddedPNG;
        code.QRCodeSettings.Mode = Telerik.Web.UI.Barcode.Modes.CodeMode.Byte;
        code.QRCodeSettings.ErrorCorrectionLevel = Telerik.Web.UI.Barcode.Modes.ErrorCorrectionLevel.L;
        code.QRCodeSettings.DotSize = iDotSize;
        code.QRCodeSettings.Version = 2;
        code.QRCodeSettings.ECI = Telerik.Web.UI.Barcode.Modes.ECIMode.None;
     
        int iToCrop = 80;
     
        var rect = new Rectangle(iToCrop/2, iToCrop/2, code.GetImage().Width - iToCrop, code.GetImage().Height - iToCrop);
        Bitmap cloned = new Bitmap(code.GetImage()).Clone(rect, code.GetImage().PixelFormat);
        var bitmap = new Bitmap(cloned, new Size(code.GetImage().Width - iToCrop, code.GetImage().Height - iToCrop));
        cloned.Dispose();
        return bitmap;
    }

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top