Creating QR Codes

I am writing an application that will generate QR codes.

Most of the programming logic is implemented.

The next step in this process will be to create a qr code image.

The simplest qr code is based on a 21x21 grid in which I have to make a tile (1x1) or black and white.

For more information: http://www.thonky.com/qr-code-tutorial/part-3-mask-pattern/

What would be the best approach for this.

I need:

  1. Preview code in app

  2. Give the user the option to save the qr code as an image (think .jpg).

That is, how to make an image that can be built as above and how to save it?

+4
source share
3 answers

To create an image of a QR code, you will need to create a bitmap image in your application. Sample code for this:

'Create a new QR bitmap image Dim bmp As New Bitmap(21, 21) 'Get the graphics object to manipulate the bitmap Dim gr As Graphics = Graphics.FromImage(bmp) 'Set the background of the bitmap to white gr.FillRectangle(Brushes.White, 0, 0, 21, 21) 'Draw position detection patterns 'Top Left gr.DrawRectangle(Pens.Black, 0, 0, 6, 6) gr.FillRectangle(Brushes.Black, 2, 2, 3, 3) 'Top Right gr.DrawRectangle(Pens.Black, 14, 0, 6, 6) gr.FillRectangle(Brushes.Black, 2, 16, 3, 3) 'Bottom Left gr.DrawRectangle(Pens.Black, 0, 14, 6, 6) gr.FillRectangle(Brushes.Black, 16, 2, 3, 3) '*** Drawing pixels is done off the bitmap object, not the graphics object 'Arbitrary black pixel bmp.SetPixel(8, 14, Color.Black) 'Top timing pattern bmp.SetPixel(8, 6, Color.Black) bmp.SetPixel(10, 6, Color.Black) bmp.SetPixel(12, 6, Color.Black) 'Left timing pattern bmp.SetPixel(6, 8, Color.Black) bmp.SetPixel(6, 10, Color.Black) bmp.SetPixel(6, 12, Color.Black) 'Add code here to set the rest of the pixels as needed 

To display the image to the end user, you can use the PictureBox control:

 Me.PictureBox1.Image = bmp 

And finally, to save the bitmap, you can call the save function on it:

 bmp.Save("C:\QR.jpg", Drawing.Imaging.ImageFormat.Jpeg) 
+4
source

I would personally try using the Google Charts service to generate the qr code image. Simply and easily. Here is an example image from Google.

https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=Hello%20world&choe=UTF-8

Check out the docs here: http://code.google.com/apis/chart/infographics/docs/qr_codes.html

+5
source

In my opinion, one of the best and easiest options is to look at the next plugin.

Link

Here you can find a DLL to directly add to your window / web application. It also supports both VB and C #. The source file also contains a sample for VB and C #

0
source

All Articles