douqiao5543 2014-11-13 04:03
浏览 24
已采纳

从100 x 100 QR代码创建2D位阵列

Given a QR Code of dimensions 100 x 100, I need to make a 2D bit array (array[100][100] that will hold 1 or 0). To get a better idea of the array I am trying to make, look at the array given in this Stack Overflow question.

After hours of searching, I found a function on Google Code that would appear to get the job done. The problem is that the code is given in a .go file, which my computer cannot open.

The ideal solution would either offer a solution in another language, or suggest the way I should go about using the code I found on Google Code.

Thank you in advance for your help!

  • 写回答

1条回答 默认 最新

  • duanjiao3754 2014-11-13 09:01
    关注

    If you are looking for encoding an url (or other text) to a QR code array and show a textual presentation of the 2D array, you can rather easily make a command line tool to do this in Go.
    Below is a fully working example of such a tool using the go package you mentioned.

    In order to compile it and run it, go to http://golang.org where you can find instructions on how to install Go, install external libraries, and compile the tool:

    package main
    
    import (
        "flag"
        "fmt"
        "os"
    
        "code.google.com/p/go-qrcode"
    )
    
    var (
        url   = flag.String("url", "", "Url to encode")
        level = flag.Int("level", 0, "Recovery level. 0 is lowest, 3 is highest")
    )
    
    func main() {
        flag.Parse()
    
        if *level < 0 || *level > 3 {
            fmt.Println("Level must be between 0 and 3")
            os.Exit(1)
        }
    
        qr, err := qrcode.New(*url, qrcode.RecoveryLevel(*level))
        if err != nil {
            fmt.Println(err)
            os.Exit(1)
        }
    
        printArray(qr.Bitmap())
    }
    
    func printArray(a [][]bool) {
        fmt.Println("{")
        for _, x := range a {
            fmt.Print("  {")
            out := ""
            for _, y := range x {
                if y {
                    out += "1"
                } else {
                    out += "0"
                }
                fmt.Print(out)
                out = ","
            }
            fmt.Println("}")
        }
        fmt.Println("}")
    }
    

    Usage:

    Usage of qrarray.exe:
      -level=0: Recovery level. 0 is lowest, 3 is highest
      -url="": Url to encode
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示