dreamingWorld
Intern
Intern
  • UID13434
  • Fans0
  • Follows0
  • Posts3
Reads:765Replies:0

QR code asp net core

Created#
More Posted time:Oct 26, 2022 19:12 PM
Creating QR Code in asp.net core is important part of application development nowadays, so we can easily scan QR Code and get information about product or pay a payement etc.
ZXing.NET is used to generate QR Code in ASP.NET Core
Here is sample code

 var writer = new QRCodeWriter();
            //generate QR Code
            var resultBit = writer.encode(formCollection["QrCodeString"], BarcodeFormat.QR_CODE, 200, 200);
            //get Bitmatrix result
            var matrix = resultBit;

            //convert bitmatrix into image
            int scale = 2;

            Bitmap result = new Bitmap(matrix.Width * scale, matrix.Height * scale);
            for (int x = 0; x < matrix.Height; x++)
                for (int y = 0; y < matrix.Width; y++)
                {
                    Color pixel = matrix[x, y] ? Color.Black : Color.White;
                    for (int i = 0; i < scale; i++)
                        for (int j = 0; j < scale; j++)
                            result.SetPixel(x * scale + i, y * scale + j, pixel);
                }

Thanks.
Guest