golang如何生成與讀取二維碼

golang如何生成與讀取二維碼

生成二維碼

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, 256)

    file, _ := os.Create("qr2.png")
    defer file.Close()

    png.Encode(file, qrCode)
}

識(shí)別二維碼

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)
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • 太長(zhǎng)了,還是轉(zhuǎn)載吧...今天在看博客的時(shí)候,無(wú)意中發(fā)現(xiàn)了@Trinea在GitHub上的一個(gè)項(xiàng)目Android開(kāi)源...
    龐哈哈哈12138閱讀 20,280評(píng)論 3 283
  • # Python 資源大全中文版 我想很多程序員應(yīng)該記得 GitHub 上有一個(gè) Awesome - XXX 系列...
    aimaile閱讀 26,593評(píng)論 6 427
  • 從來(lái)不是什么幸運(yùn)的人,沒(méi)有太偉大的夢(mèng)想,只想安靜平凡的生活。 一直希望可以嫁個(gè)平凡的男人,守著一個(gè)小鎮(zhèn),開(kāi)一間花店...
    陌九閱讀 350評(píng)論 10 8
  • 人是自由的嗎? 1、故事:《白板》中的“甜點(diǎn)抗辯”。1978年舊金山有一個(gè)警察持槍從市政大樓地下室的窗口潛入,闖進(jìn)...
    瞰川閱讀 259評(píng)論 0 0
  • 文/怡記 手機(jī)是我們經(jīng)常使用的工具,如何通過(guò)使用一些APP,讓我們的生活更美好呢? 1、簡(jiǎn)書(shū) 主要用途:閱讀、寫(xiě)作...
    怡記閱讀 3,468評(píng)論 9 45