Go实战--golang中生成读取二维码(skip2/go-qrcode和boombuler/ba
生命不止,继续go go go!!! 这里介绍一下,golang如何生成二维码,当然是面向github编程了。 QRCode百度百科: wiki: skip2/go-qrcode生成二维码github地址:https://github.com/skip2/go-qrcode 获取: go get skip2/go-qrcode
生成二维码图片: package main
import qrcode "github.com/skip2/go-qrcode"
import "fmt"
func main() {
err := qrcode.WriteFile("http://blog.csdn.net/wangshubo1989",qrcode.Medium, 256,"qr.png")
if err != nil {
fmt.Println("write error")
}
}
结果: boombuler/barcode生成二维码github地址:https://github.com/boombuler/barcode 获取: go get github.com/boombuler/barcode
生成二维码图片: package main
import (
"image/png"
"os"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
)
func main() {
qrCode,_ := qr.Encode("http://blog.csdn.net/wangshubo1989",qr.M,qr.Auto)
qrCode,_ = barcode.Scale(qrCode, 256)
file,_ := os.Create("qr2.png")
defer file.Close()
png.Encode(file,qrCode)
}
结果: tuotoo/qrcode识别二维码github地址:https://github.com/tuotoo/qrcode go get github.com/tuotoo/qrcode
读取二维码图片: package main
import (
"fmt"
"os"
"github.com/tuotoo/qrcode"
)
func main() {
fi,err := os.Open("qrcode.png")
if err != nil {
fmt.Println(err.Error())
return
}
defer fi.Close()
qrmatrix,err := qrcode.Decode(fi)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(qrmatrix.Content)
}
输出: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |