Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Save image file from qrCode or base64 in asp.net C#

I want to save qrCode as image file in application path so that I can call it on report which is created in Crystal Report.

How to save qrCode as image file or convert base64 to an image and save on physical location?

My code is below.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        TextBox6.Text = GenerateAndGetString();

        QRCodeGenerator qrGenerator = new QRCodeGenerator();
        QRCodeData qrCodeData = qrGenerator.CreateQrCode(TextBox6.Text, QRCodeGenerator.ECCLevel.Q);
        QRCode qrCode = new QRCode(qrCodeData);
        Bitmap qrCodeImage = qrCode.GetGraphic(20);

        using (Bitmap bitMap = qrCode.GetGraphic(20))
        {
            using (MemoryStream ms = new MemoryStream())
            {
                bitMap.Save(ms, ImageFormat.Png);
                byte[] byteImage = ms.ToArray();
                img.Src = "data:image/png;base64," + Convert.ToBase64String(byteImage);
            }
        }
    }
}

public String GenerateAndGetString()
{
    var sellername = TextBox1.Text;
    var vatregistration = TextBox2.Text;
    var timestamp = TextBox3.Text;
    var invoiceamount = TextBox4.Text;
    var vatamoun = TextBox5.Text;

    return ConvertBase64(sellername, vatregistration, timestamp, invoiceamount, vatamoun);
}

>Solution :

You already got the image as byte-array, so you could do something like this:

System.IO.File.WriteAllBytes(path, ms.ToArray());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading