Subscribe Us

LightBlog

Wednesday, 1 July 2020

QRCode and Barcode generate in ASP.NET MVC

In this article, i will show you how to generate QRCode and Barcode in  ASP.NET MVC
  • Add this two packages QRCoder and GenCode128
         #region QR Code Generation 
        public ActionResult GetQRCodeImage(string qrcode)
        {
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrcode,
            QRCodeGenerator.ECCLevel.Q);
            QRCode qrCode = new QRCode(qrCodeData);
            Bitmap qrCodeImage = qrCode.GetGraphic(20);
            ImageConverter converter = new ImageConverter();
            byte[] img = (byte[])converter.ConvertTo(qrCodeImage, typeof(byte[]));
            return new FileStreamResult(new System.IO.MemoryStream(img), "image/jpeg");
        }
        #endregion

        #region Bar Code Generation
        public ActionResult GetBarcodeImage(string brcode)
        {
            Image myimg = Code128Rendering.MakeBarcodeImage(brcode, int.Parse("2"), true);
            ImageConverter converter = new ImageConverter();
            byte[] img = (byte[])converter.ConvertTo(myimg, typeof(byte[]));
            return new FileStreamResult(new System.IO.MemoryStream(img), "image/jpeg");
        }
        #endregion

QRCode
QRCode
Code128
GenCode128
 

No comments:

Post a Comment