我个人会尝试使用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
为了创建 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)