工具包
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.

34 lines
595 B

  1. package zhios_tool_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. }