Hi RichardSa.
Please refer below sample code.
HTML
<asp:Image ID="Image1" runat="server" ImageUrl="data:image/png;base64,iVBORw0KGgoA..." Visible="false" />
<asp:Image ID="imgQrCode" runat="server" Height="200" Width="200" />
Namespace
C#
using QRCoder;
using System.IO;
using System.Drawing;
VB.Net
Imports QRCoder
Imports System.IO
Imports System.Drawing
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
imgQrCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(GetQRCode());
}
public byte[] GetQRCode()
{
byte[] image = Convert.FromBase64String(Image1.ImageUrl.Replace("data:image/png;base64,", String.Empty));
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode("https://www.aspsnippets.com", QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
using (Bitmap logo = (Bitmap)Bitmap.FromStream(new MemoryStream(image)))
{
using (MemoryStream ms = new MemoryStream())
{
// Specify the Size in percentage. Here it is specified as 30.
using (Bitmap qrCodeImage = qrCode.GetGraphic(40, Color.Black, Color.Transparent, logo, 30, 0, true, Color.Transparent))
{
qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
}
return ms.ToArray();
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
imgQrCode.ImageUrl = "data:image/png;base64," & Convert.ToBase64String(GetQRCode())
End Sub
Public Function GetQRCode() As Byte()
Dim image As Byte() = Convert.FromBase64String(Image1.ImageUrl.Replace("data:image/png;base64,", String.Empty))
Dim qrGenerator As QRCodeGenerator = New QRCodeGenerator()
Dim qrCodeData As QRCodeData = qrGenerator.CreateQrCode("https://www.aspsnippets.com", QRCodeGenerator.ECCLevel.Q)
Dim qrCode As QRCode = New QRCode(qrCodeData)
Using logo As Bitmap = CType(Bitmap.FromStream(New MemoryStream(image)), Bitmap)
Using ms As MemoryStream = New MemoryStream()
' Specify the Size in percentage. Here it is specified as 30.
Using qrCodeImage As Bitmap = qrCode.GetGraphic(40, Color.Black, Color.Transparent, logo, 30, 0, True, Color.Transparent)
qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
End Using
Return ms.ToArray()
End Using
End Using
End Function
Screenshot