QR code drawing

May 10, 2012 at 4:53 PM

I read how to draw with C# but i don't know how to integrate it with this code and generate the QR Code. Is there any documentation to enlighten me about this topic?

 

thanks in advance.

Nov 12, 2012 at 9:35 PM

I am having same issue. Anyone figure this out yet?

Jul 9, 2013 at 4:25 PM
ON ASP.Net (VB)
Example of it running from visual studio:
http://localhost:55761/QR.aspx?s=6&t=ThisIsMyText
Option Explicit On
Option Strict On

Imports QRCode4CS
Imports System.Drawing

Partial Class QR
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        Dim isDark As Boolean
        Dim square As Integer
        Dim qr As QRCode4CS.QRCode
        Dim oBitmap As Bitmap
        Dim oGraphic As Graphics
        Dim oBlack As New SolidBrush(Color.Black)
        Dim oWhite As New SolidBrush(Color.White)
        Dim text As String = ""
        Dim scale As Integer = 6

        If Request.Item("t") IsNot Nothing Then
            text = Request.Item("t").ToString
        Else
            Throw New Exception("Error generating QR code: missing data to print")
        End If

        If Request.Item("s") IsNot Nothing Then
            scale = CInt(Request.Item("s"))
        End If

        qr = New QRCode4CS.QRCode(New QRCode4CS.Options(text))
        qr.Make()
        square = qr.GetModuleCount

        If square > 0 Then

            oBitmap = New Bitmap(square * scale, square * scale)
            oGraphic = Graphics.FromImage(oBitmap)
            oGraphic.FillRectangle(New SolidBrush(Color.White), 0, 0, square * scale, square * scale)

            For row As Integer = 0 To square - 1
                For col As Integer = 0 To square - 1

                    isDark = qr.IsDark(row, col)
                    If isDark Then
                        oGraphic.FillRectangle(oBlack, row * scale, col * scale, scale, scale)
                    End If

                Next
            Next

            Response.ContentType = "image/jpeg"
            oBitmap.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg)

        Else

            Throw New Exception("Error generating QR code")

        End If

    End Sub


End Class
Dec 27, 2013 at 1:12 AM
C# Example

I finished this today, so I thought I'd share. Create a QR Code saying "Hello World" in pictureBox1
/**
 * QR Code for C# - Full Working Example
 * @author Josh Richard <josh.richard@gmail.com>
 * @license MIT
 * @license http://theyconfuse.me/license/mit
 */

/**
 * @type string The data to encode in the QR Code
 */
string QRText = "Hello World";

/**
 * @type int The pixel size of each "block" in the QR Code; change this to adjust the size
 */
int blockSize = 5;

/**
 * Create the QR Code
 */
QRCode4CS.QRCode QRCoded = new QRCode4CS.QRCode(new QRCode4CS.Options(QRText));
QRCoded.Make();

/**
 * Create a blank bitmap to draw on
 */
Bitmap DrawArea = new Bitmap((QRCoded.GetModuleCount() * blockSize), (QRCoded.GetModuleCount() * blockSize));

/**
 * Draw the QR Code in the bitmap
 */
 for (int row = 0; row < QRCoded.GetModuleCount(); row++)
   {
       for (int col = 0; col < QRCoded.GetModuleCount(); col++)
       {
           bool isDark = QRCoded.IsDark(row, col);
           if (isDark)
           {
                for (int y = 0; y < blockSize; y++)
                {
                    int myCol = (blockSize * (col - 1)) + (y + blockSize);
                    for (int x = 0; x < blockSize; x++)
                    {
                        DrawArea.SetPixel((blockSize * (row - 1)) + (x + blockSize), myCol, Color.Black);
                    }
                }
           }
           else
           {
                for (int y = 0; y < blockSize; y++)
                {
                    int myCol = (blockSize * (col - 1)) + (y + blockSize);
                    for (int x = 0; x < blockSize; x++)
                    {
                        DrawArea.SetPixel((blockSize * (row - 1)) + (x + blockSize), myCol, Color.White);
                    }
                }
           }
       }
   }
   
/**
 * Set the picture box image to the new bitmap
 */
pictureBox1.Image = DrawArea;
Mar 1, 2014 at 1:24 AM
hi there!

I ve been adapting this code,
thank u very much

when trying to generate a QR
as long as 40 chars or more
it draws nothing

any clue on how to unlock this limitation?
Mar 21, 2014 at 8:25 AM
Hi, maybe you can change your QR Code version settings, a Version 40 QR Code can encode up to over 4000 alphanumeric characters. Also you can try lower the ECL (Error Correction Level) to encode more data. You can view about QR Code settings here.