Create QR Code Using Google Charts API In VB.Net

Here we learn about how to generate QR Code Using Google API In Vb.Net

Step 1

Design a windows form as per below picture that contains Label, Textbox to get text for QR Code, and One Button for QR Code Generation and one PictureBox to show QR Code.

Step 2

Give textbox name as txtqrcode and button name as btnqrcode and picturebox name as picturebox1 and set picturebox width and height 300 and sizemode = stretchimage

Step 3

Google API Link for generating QR Code

Step 4

Write following code in btnQRCode button's click event


Private Sub btnQRCode_Click(sender As System.Object, e As System.EventArgs) Handles btnQRCode.Click
        If txtQRCode.Text <> "" Then
            Dim strQR As String
            strQR = txtQRCode.Text

            Dim QrLink As String = ""
            QrLink = QrLink & strQR

            Using webClient As Net.WebClient = New Net.WebClient
                Const _Tls12 As SslProtocols = CType(&HC00, SslProtocols)
                Const Tls12 As SecurityProtocolType = CType(_Tls12, SecurityProtocolType)
                ServicePointManager.SecurityProtocol = Tls12
                Dim data As Byte() = webClient.DownloadData(QrLink)
                Dim newImage As Image = byteArrayToImage(data)
                PictureBox1.Image = newImage
            End Using
            MsgBox("Please Enter Something")
        End If
End Sub


private void btnQRCode_Click(System.Object sender, System.EventArgs e)
    if (txtQRCode.Text != "")
        string strQR;
        strQR = txtQRCode.Text;

        string QrLink = "";
        QrLink = QrLink + strQR;

        using (System.Net.WebClient webClient = new System.Net.WebClient())
            const SslProtocols _Tls12 = (SslProtocols)0xC00;
            const SecurityProtocolType Tls12 = (SecurityProtocolType)_Tls12;
            ServicePointManager.SecurityProtocol = Tls12;
            byte[] data = webClient.DownloadData(QrLink);
            Image newImage = byteArrayToImage(data);
            PictureBox1.Image = newImage;
        Interaction.MsgBox("Please Enter Something");

byteArrayToImage() function code as below


Public Function byteArrayToImage(ByVal byteArrayIn As Byte()) As Image
        Using ms = New MemoryStream(byteArrayIn)
            Return Image.FromStream(ms)
        End Using
End Function


public Image byteArrayToImage(byte[] byteArrayIn)
    using (var ms = new MemoryStream(byteArrayIn))
        return Image.FromStream(ms);

Here in Google API height and weight is 300 * 300 and our PictureBox1 size is same 300 * 300

Step 5

Run your application, and type something to generate QR Code as per following

Step 6

After typing click on generate QR code button and your QR code is ready and shown into picturebox as following

When you scan this QR you can get exact data like 'uday dodiya QR code' or you can generate QR code for any data


Generating QR code using google API is so easy

Without using messagingtoolkit generate QR code