makiuchi-d / gozxing

Port of ZXing (https://github.com/zxing/zxing) core to pure Go.
Other
565 stars 65 forks source link

panic: runtime error: invalid memory address or nil pointer dereference #25

Closed zinwalin closed 5 years ago

zinwalin commented 5 years ago

panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x20 pc=0x4b60be]

goroutine 1 [running]: github.com/makiuchi-d/gozxing.NewLuminanceSourceFromImage(0x0, 0x0, 0xc00007e070, 0x0) C:/src/go_work/src/github.com/makiuchi-d/gozxing/go_image_luminance_source.go:19 +0x3e github.com/makiuchi-d/gozxing.NewBinaryBitmapFromImage(0x0, 0x0, 0x0, 0x0, 0x0) C:/src/go_work/src/github.com/makiuchi-d/gozxing/go_image_luminance_source.go:10 +0x40 main.main() C:/src/go_work/src/learning/qrcode.go:36 +0x85 exit status 2



package main

import (
    "fmt"
    "image"
    _ "image/jpeg"
    "os"

    "github.com/makiuchi-d/gozxing"
    "github.com/makiuchi-d/gozxing/qrcode"
)

func main() {
    // open and decode image file
    file, _ := os.Open("qr.png")
    img, _, _ := image.Decode(file)

    // prepare BinaryBitmap
    bmp, _ := gozxing.NewBinaryBitmapFromImage(img)

    // decode image
    qrReader := qrcode.NewQRCodeReader()
    result, _ := qrReader.Decode(bmp, nil)

    fmt.Println(result)
}
makiuchi-d commented 5 years ago

github.com/makiuchi-d/gozxing.NewBinaryBitmapFromImage(0x0, 0x0, 0x0, 0x0, 0x0)

It means img is nil. This comes from a problem with your image file (qr.png).