生成QR码

Pee*_*Haa 4 vb.net qr-code image

我正在编写一个将生成qr代码的应用程序.

大多数编程逻辑都已实现.

该过程的下一步是生成qr代码图像.

最简单的qr代码基于一个21x21网格,我必须在其中制作一个黑色/白色的瓷砖(1x1).

欲了解更多信息:http://www.thonky.com/qr-code-tutorial/part-3-mask-pattern/

什么是最好的方法.

我需要:

  1. 显示应用程序中代码的预览
  2. 为用户提供将qr代码保存为图像的选项(我认为是.jpg).

即如何制作可以像上面那样构建的图像以及如何保存它?

任何帮助表示赞赏.

Joh*_*n P 5

我个人会尝试使用Google图表服务来生成qr代码图像.简单易用.以下是Google网站的示例图片.

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

在此处查看文档:http: //code.google.com/apis/chart/infographics/docs/qr_codes.html

  • 并不是我的问题的答案。下一步是什么?建议使用正则表达式/ jQuery?;) (2认同)

bri*_*ums 4

为了创建 QR 码图像,您需要在应用程序中生成位图。执行此操作的示例代码是:

'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
Run Code Online (Sandbox Code Playgroud)

为了向最终用户显示图像,您可以使用 PictureBox 控件:

Me.PictureBox1.Image = bmp
Run Code Online (Sandbox Code Playgroud)

最后,为了保存位图,您可以对其调用 save 函数:

bmp.Save("C:\QR.jpg", Drawing.Imaging.ImageFormat.Jpeg)
Run Code Online (Sandbox Code Playgroud)