0
Metodo utilizando a biblioteca QRCoder.
using QRCoder.
public class GerarQRCoder
{
public static void GerarQR(TextBox txtQRCode)
{
string Cd = txtQRCode.Text.ToString();
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(Cd, QRCodeGenerator.ECCLevel.Q);
Base64QRCode qrCode = new Base64QRCode(qrCodeData);
// string qrCodeImageAsBase64 = qrCode.GetGraphic(20);
var imgType = Base64QRCode.ImageType.Jpeg;
///Base64QRCode qrCode = new Base64QRCode(qrCodeData);
string qrCodeImageAsBase64 = qrCode.GetGraphic(20, Color.Black, Color.White, true, imgType);
var htmlPictureTag = $"<img alt=\"Embedded QR Code\" src=\"data:image/{imgType.ToString().ToLower()};base64,{qrCodeImageAsBase64}\" />";
}
}
}
I have used the ASP. so however I can not pass the src of the correct image to generate the image on the screen, someone could help me please.
<asp:Button ID="btnGenerate" runat="server" OnClick="btnGenerate_Click" Text="Gerar QRcode" />
<asp:Image ID="ImgQRCode" runat="server" src= "src="data:image/{imgType.ToString().ToLower()};base64,{qrCodeImageAsBase64}"
alt="QR Code" Height="207px" Width="219px"/>
</p>
I could not understand the relationship between the two blocks of code, the method should not return the string with the contents of QR in Base64?
– Leandro Angelo
Hello Leandro sorry the delay, my doubt is exactly how to return this address to the image src"" actually just like this: <Asp:Image ID="Imgqrcode" runat="server" src= """/>, and I can’t pass the address to generate the image.
– Rubens Cordeiro
It seems to me that you are working with webforms, you can assign this source by backend on
btnGenerate_Click
or expose a webmethod to make this request via ajax for example– Leandro Angelo