Generate and display QR code image using QR Code library in

In this article I am going to explain how to generate and display QR code image using QR Code library in (C#,
Generate and display QR code image using QR Code library in asp net

Implementation :

HTML Markup:

 <fieldset style="width:30%">
        <legend>Generate QR Code Example</legend>
        <tr><td>Enter URL OR Text:</td><td><asp:TextBox ID="txturl" runat="server"></asp:TextBox></td></tr>
        <tr><td colspan="2"><asp:Image runat="server" ID="QRImage" /></td></tr>
        <tr><td></td><td><asp:Button ID="btnsubmit"
            runat="server" Text="Generate QR Code"/></td></tr>

To install Qr Code library, run the following command in the Package Manager Console
Install-Package MessagingToolkit.QRCode

Add the namespace:
C# code:
using MessagingToolkit.QRCode.Codec;
using MessagingToolkit.QRCode.Codec.Data;

using System.Drawing;
using System.Drawing.Imaging; code:
Imports MessagingToolkit.QRCode.Codec
Imports MessagingToolkit.QRCode.Codec.Data
Imports System.Drawing
Imports System.Drawing.Imaging

On button click write the below given code:
C# code:
protected void btnsubmit_Click(object sender, EventArgs e)
        QRCodeEncoder encoder = new QRCodeEncoder();
        encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H;
        encoder.QRCodeScale = 10;
        Bitmap img = encoder.Encode(txturl.Text);
        img.Save(Server.MapPath("image/") + "qrimage.png", ImageFormat.Png);
        QRImage.ImageUrl = "image/qrimage.png";      
        catch(Exception ex)
    } code:
   Protected Sub btnsubmit_Click(sender As Object, e As System.EventArgs) Handles btnsubmit.Click
        Dim encoder As New QRCodeEncoder()
        encoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H
        encoder.QRCodeScale = 10
        Dim img As Bitmap = encoder.Encode(txturl.Text)
        img.Save(Server.MapPath("image/") + "qrimage.png", ImageFormat.Png)
        QRImage.ImageUrl = "image/qrimage.png"
    End Sub

Post a Comment

saludos, y si quisiera cambiar el color del QR cual seria el codigo



Contact Form


Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget