Hi counterkin,
Refer below code.
Namespaces
using QRCoder;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string qrcode)
{
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrcode, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
using (Bitmap bitMap = qrCode.GetGraphic(5))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, ImageFormat.Png);
Image image = bitMap;
using (Graphics graphics = Graphics.FromImage(bitMap))
{
graphics.DrawString(qrcode, new Font("Arial", 10), Brushes.Red, new PointF(30f, 125f));
graphics.DrawImage(image, new Rectangle(new Point(0, 0), image.Size));
MemoryStream stream = new MemoryStream();
bitMap.Save(stream, ImageFormat.Png);
ViewBag.QRCodeImage = "data:image/png;base64," + Convert.ToBase64String(stream.ToArray());
}
}
}
return View();
}
}
View
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<form asp-action="Index" asp-controller="Home">
<input type="text" name="qrcode" />
<input type="submit" value="Generate" />
</form>
@if (ViewBag.QRCodeImage != null)
{
<img src="@ViewBag.QRCodeImage" alt="" style="height:150px;width:150px" />
}
</body>
</html>
Screenshot