You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
874 B
49 lines
874 B
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"image"
|
|
_ "image/png" // Required to decode PNG files
|
|
"log"
|
|
"flag"
|
|
"os"
|
|
|
|
"github.com/makiuchi-d/gozxing"
|
|
"github.com/makiuchi-d/gozxing/qrcode"
|
|
)
|
|
|
|
func main() {
|
|
input := flag.String("input", "qrcode.png", "Input filename for QR code")
|
|
flag.Parse()
|
|
|
|
// Open the PNG file
|
|
file, err := os.Open(*input)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
// Decode the image
|
|
img, _, err := image.Decode(file)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Convert image to BinaryBitmap
|
|
bmp, err := gozxing.NewBinaryBitmapFromImage(img)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Prepare a QR code reader
|
|
reader := qrcode.NewQRCodeReader()
|
|
|
|
// Decode the QR code
|
|
result, err := reader.Decode(bmp, nil)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Print the decoded content
|
|
fmt.Println("Decoded QR code:", result.GetText())
|
|
}
|
|
|