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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)