Hi @Donald Symmons,
I wrote an example according to your needs, you can refer to:
<asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
<asp:Button ID="btnGenerate" runat="server" Text="Generate" OnClick="btnGenerate_Click" />
<hr />
<asp:Image ID="LogoImage" runat="server" />
<asp:Image ID="QRImage1" runat="server" Width="150" Height="150" />
protected void Page_Load(object sender, EventArgs e)
{
Showdata1();
}
public void Showdata1()
{
//In this public void, the logo image is read from the database table and displayed on the web form.
string connectionString = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM tblFiles WHERE Id = 1", con))
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
byte[] bytes = (byte[])dr["Data"];
LogoImage.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(bytes);
}
}
}
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
string code = txtCode.Text;
byte[] image = Convert.FromBase64String(LogoImage.ImageUrl.Replace("data:image/jpeg;base64,", String.Empty));
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData);
using (Bitmap bitMap = qrCode.GetGraphic(40))
{
Bitmap overlay = new Bitmap(new MemoryStream(image));
int deltaHeigth = bitMap.Height - overlay.Height;
int deltaWidth = bitMap.Width - overlay.Width;
Graphics g = Graphics.FromImage(bitMap);
g.DrawImage(overlay, new System.Drawing.Point(deltaWidth / 2, deltaHeigth / 2));
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
QRImage1.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
}
}
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.