Hi anirudhp,
Refer below sample.
Refer below article and download the QRcoder dll.
Namespaces
C#
using QRCoder;
using System.IO;
using System.Drawing.Imaging;
VB.Net
Imports QRCoder
Imports System.IO
Imports System.Drawing.Imaging
Code
C#
private void btnGenerate_Click(object sender, EventArgs e)
{
string code = txtCode.Text;
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeGenerator.QRCode qrCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
Bitmap bitMap = qrCode.GetGraphic(5);
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
pictureBox1.Image = bitMap;
pictureBox1.Height = bitMap.Height;
pictureBox1.Width = bitMap.Width;
}
int x1 = 0;
int x2 = Math.Max(pictureBox1.Image.Width, pictureBox1.Image.Width);
int y1 = 0;
int y2 = Math.Max(pictureBox1.Image.Height, pictureBox1.Image.Height);
Rectangle rect1 = new Rectangle(new Point(x1, y1), pictureBox1.Image.Size);
PointF firstLocation = new PointF(30f, 125f);
PointF secondLocation = new PointF(30f, 50f);
using (Graphics graphics = Graphics.FromImage(bitMap))
{
using (Font arialFont = new Font("Arial", 12))
{
graphics.DrawString(code, arialFont, Brushes.Black, firstLocation);
graphics.DrawImage(pictureBox1.Image, rect1);
}
bitMap.Save(@"C:\Users\anand\Desktop\Test.png", ImageFormat.Png);
}
}
VB.Net
Private Sub btnGenerate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
Dim code As String = txtCode.Text
Dim qrGenerator As QRCodeGenerator = New QRCodeGenerator()
Dim qrCode As QRCodeGenerator.QRCode = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q)
Dim bitMap As Bitmap = qrCode.GetGraphic(5)
Using ms As MemoryStream = New MemoryStream()
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
pictureBox1.Image = bitMap
pictureBox1.Height = bitMap.Height
pictureBox1.Width = bitMap.Width
End Using
Dim x1 As Integer = 0
Dim x2 As Integer = Math.Max(pictureBox1.Image.Width, pictureBox1.Image.Width)
Dim y1 As Integer = 0
Dim y2 As Integer = Math.Max(pictureBox1.Image.Height, pictureBox1.Image.Height)
Dim rect1 As Rectangle = New Rectangle(New Point(x1, y1), pictureBox1.Image.Size)
Dim firstLocation As PointF = New PointF(30.0F, 125.0F)
Dim secondLocation As PointF = New PointF(30.0F, 50.0F)
Using graphics As Graphics = graphics.FromImage(bitMap)
Using arialFont As Font = New Font("Arial", 12)
graphics.DrawString(code, arialFont, Brushes.Black, firstLocation)
graphics.DrawImage(pictureBox1.Image, rect1)
End Using
bitMap.Save("C:\Users\anand\Desktop\Test.png", ImageFormat.Png)
End Using
End Sub
Screenshot