Git Product home page Git Product logo

Comments (4)

codebude avatar codebude commented on August 24, 2024 6

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 81e6ea9

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

from qrcoder.

codebude avatar codebude commented on August 24, 2024

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! ;-)

from qrcoder.

milenstack avatar milenstack commented on August 24, 2024

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

from qrcoder.

codebude avatar codebude commented on August 24, 2024

Hey @gujunxiong ,

thanks for your work. I added it with minimal changes to the repository. 4cf2d42

from qrcoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.