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!
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