This is a migrated thread and some comments may be shown as answers.

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

1 Answer 1732 Views
Barcode
This is a migrated thread and some comments may be shown as answers.
kzimny
Top achievements
Rank 1
kzimny asked on 09 Sep 2016, 12:58 PM
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

1 Answer, 1 is accepted

Sort by
0
kzimny
Top achievements
Rank 1
answered on 13 Sep 2016, 06:31 AM

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;
}

Tags
Barcode
Asked by
kzimny
Top achievements
Rank 1
Answers by
kzimny
Top achievements
Rank 1
Share this question
or