Removing the border
Hey there!
First of all, thanks for all your hard work, it's a really nice library. :+1:
I was wondering how I'd go about removing the white border? I'll make sure to add some white-space around it in my CSS, it's pretty difficult to place and scale responsively with the border, so I'd rather just do it without.
You can consider this a feature request also! :-)
Hey Codeshare-NET,
you could change the GetGraphic method. There you could edit the both for loops which render the QRCode graphics by increment/decrementing the loop-count by the border's width.
Or you'll wait 2-3 days and I'll do it and update the project... But it's open source - so just try it! ;-)
Hi @Codeshark-NET ,
I added an parameter named "drawQuietZones". If you set it to false, the quiet zones around the QR code won't be drawn. If you want to see the changes, have a look at https://github.com/codebude/QRCoder/commit/81e6ea904464083a1245ff4afefaa6b25e086fef
Also you wrote about CSS, so it sounds like you want to embed the QR code inside a web application. Have you seen that the library also supports SVG as output format? https://github.com/codebude/QRCoder/blob/master/QRCoder/SvgQRCode.cs
public string GetGraphic(Size viewBox, string darkColorHex, string lightColorHex, bool drawQuietZones = false)
{
StringBuilder svgFile = new StringBuilder($@"<svg version=""1.1"" baseProfile = ""full"" width=""{viewBox.Width}"" height=""{viewBox.Height}"" xmlns=""http://www.w3.org/2000/svg"">");
int unitsPerModule = (int)Math.Floor(Convert.ToDouble(Math.Min(viewBox.Width, viewBox.Height)) / qrCodeData.ModuleMatrix.Count);
var size = (qrCodeData.ModuleMatrix.Count - (drawQuietZones ? 0 : 6)) * unitsPerModule;
int offset = drawQuietZones ? 0 : 3 * unitsPerModule;
int drawableSize = size + offset;
for (int x = 0; x < drawableSize; x = x + unitsPerModule)
{
for (int y = 0; y < drawableSize; y = y + unitsPerModule)
{
var module = qrCodeData.ModuleMatrix[(y + unitsPerModule) / unitsPerModule - 1][(x + unitsPerModule) / unitsPerModule - 1];
svgFile.Append($@"<rect x=""{x - offset}"" y=""{y - offset}"" width=""{unitsPerModule}' height=""{unitsPerModule}"" fill=""{(module ? darkColorHex : lightColorHex)}"" />");
}
}
svgFile.Append(@"</svg>");
return svgFile.ToString();
}
code style is c# 6
Hey @gujunxiong ,
thanks for your work. I added it with minimal changes to the repository. https://github.com/codebude/QRCoder/commit/4cf2d42592027c3771883df84e021995ff3f5435