Thursday, December 20, 2012

How to use QR code in ASP.NET MVC?

The lib is: QRCODENET
http://qrcodenet.codeplex.com/


public ActionResult QRImage(int id)
        {
            string url = string.Format("http://myevents.apphb.com/event/details/{0}", id);
            QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H);
            QrCode qrCode = qrEncoder.Encode(url);

            GraphicsRenderer renderer = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);
            MemoryStream ms = new MemoryStream();
            renderer.WriteToStream(qrCode.Matrix, ImageFormat.Png, ms);
            byte[] image = ms.ToArray(); ;
            return File(image, "image/png");
        }

No comments:

Post a Comment