蛋蛋星球-客户端
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.

decodeFile.go 584 B

3 viikkoa sitten
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. }