首页
学习
活动
专区
圈层
工具
发布

生成QR码
EN

Stack Overflow用户
提问于 2011-08-20 20:15:11
回答 2查看 22.8K关注 0票数 5

我正在编写一个应用程序,它将生成qr代码。

大多数编程逻辑都是实现的。

该过程的下一步将是生成qr代码映像。

最简单的qr代码是基于一个21x21网格,在这个网格中,我必须制作一个(1x1)块(1x1),或者是黑色/白色。

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

最好的方法是什么。

我需要:

application

  • Give中的
  1. 显示了一个预览代码,用户可以选择将qr代码保存为一个图像(.jpg,我认为).

例如,如何制作一个像上面这样的图像,以及如何保存它?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-08-21 00:30:39

为了创建QR代码映像,您需要在应用程序中生成一个位图。这样做的示例代码是:

代码语言:javascript
复制
'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

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

代码语言:javascript
复制
Me.PictureBox1.Image = bmp

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

代码语言:javascript
复制
bmp.Save("C:\QR.jpg", Drawing.Imaging.ImageFormat.Jpeg)
票数 4
EN

Stack Overflow用户

发布于 2011-08-20 20:33:27

我个人会尝试使用谷歌图表服务,以生成qr代码图像。简单又简单。这是谷歌网站上的一个例子。

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

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7134398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档