0

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!

Community
  • 1
  • 1
pkshultz
  • 409
  • 1
  • 3
  • 16
  • You can open an `.go` file in any text editor (notepad for example), or view the file in your web browser (the link you've posted) – topskip Nov 13 '14 at 08:46
  • 2
    Not sure what you try to do. "Given a QR Code"; in what format? Png image? Printed on paper? The source you referred to is used for encoding QR's, not decoding. – ANisus Nov 13 '14 at 10:36
  • The QR Code is given in the format of a PNG, and had encoded a URL that I know. ANisus, your solution would appear to work seeing as there are parameters for URL encoding. – pkshultz Nov 13 '14 at 18:11

1 Answers1

4

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
ANisus
  • 74,460
  • 29
  • 162
  • 158
  • Please mention what is wrong with the answer if voting down, since it surely does work if the OP is trying to achieve this. – ANisus Nov 13 '14 at 10:11
  • Thanks a ton! This question was perfect, and your answer was awesome. I did add one line to force it to disable the border: qr.DisableBorder = true – Eradicatore Dec 14 '19 at 15:38