智慧食堂
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233
  1. package qrcode
  2. import (
  3. "image"
  4. _ "image/jpeg"
  5. _ "image/png"
  6. "os"
  7. "github.com/makiuchi-d/gozxing"
  8. "github.com/makiuchi-d/gozxing/qrcode"
  9. )
  10. func DecodeFile(fi string) (string, error) {
  11. file, err := os.Open(fi)
  12. if err != nil {
  13. return "", err
  14. }
  15. img, _, err := image.Decode(file)
  16. if err != nil {
  17. return "", err
  18. }
  19. // prepare BinaryBitmap
  20. bmp, err := gozxing.NewBinaryBitmapFromImage(img)
  21. if err != nil {
  22. return "", err
  23. }
  24. // decode image
  25. result, err := qrcode.NewQRCodeReader().Decode(bmp, nil)
  26. if err != nil {
  27. return "", err
  28. }
  29. return result.String(), nil
  30. }