日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

记-myqr流程

發(fā)布時(shí)間:2024/10/12 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 记-myqr流程 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

知識(shí)點(diǎn)來(lái)源網(wǎng)絡(luò)

1.MyQR文件結(jié)構(gòu)

qrcode │ LICENSE.md │ README.md │ requirements.txt #環(huán)境依賴文件 | myqr.py | └───MyQR │ │ __init__.py │ │ myqr.py #調(diào)用的文件 │ │ terminal.py #設(shè)置參數(shù) | | │ └───mylibs │ │ __init__.pt │ │ constan.py #數(shù)據(jù)分析 | | data.py #數(shù)據(jù)編碼 │ │ ECC.py #糾錯(cuò)編碼,Error Correction Codewords | | structure.py #數(shù)據(jù)結(jié)構(gòu) | | matrix.py #獲得QR矩陣 | | draw.py #生成二維碼 | | theqrmodule.py #結(jié)合函數(shù) │ └───example │ 0.png │ 1.png | 2.png | ...

2.生成二維碼的步驟

2.1 數(shù)據(jù)分析MyQR/mylibs/constan.py

確定編碼的字符類型,按相應(yīng)的字符集轉(zhuǎn)換成符號(hào)字符。

2.2 數(shù)據(jù)編碼MyQR/mylibs/data.py

將數(shù)據(jù)字符轉(zhuǎn)換為位流,每8位一個(gè)碼字,整體構(gòu)成一個(gè)數(shù)據(jù)的碼字序列。

2.3 糾錯(cuò)編碼MyQR/mylibs/ECC.py

按需要將上面的碼字序列分塊,并根據(jù)糾錯(cuò)等級(jí)和分塊的碼字,產(chǎn)生糾錯(cuò)碼字,并把糾錯(cuò)碼字加入到數(shù)據(jù)碼字序列后面,成為一個(gè)新的序列。

2.4 構(gòu)造最終數(shù)據(jù)信息MyQR/mylibs/structure.py + matrix.py

在規(guī)格確定的條件下,將上面產(chǎn)生的序列按次序放入分塊中,將數(shù)據(jù)轉(zhuǎn)成能夠畫出二維碼的矩陣。

創(chuàng)建二維碼的矩陣

# MyQR/mylibs/matrix.py def get_qrmatrix(ver, ecl, bits):num = (ver - 1) * 4 + 21 qrmatrix = [[None] * num for i in range(num)] # 添加查找器模式和添加分隔符 add_finder_and_separator(qrmatrix) # 添加校準(zhǔn)模式 add_alignment(ver, qrmatrix) # 添加時(shí)間模式 add_timing(qrmatrix) # 添加涂黑模塊和保留區(qū)域 add_dark_and_reserving(ver, qrmatrix) maskmatrix = [i[:] for i in qrmatrix] # 放置數(shù)據(jù)位 place_bits(bits, qrmatrix) # 蒙版操作 mask_num, qrmatrix = mask(maskmatrix, qrmatrix) # 格式信息 add_format_and_version_string(ver, ecl, mask_num, qrmatrix) return qrmatrix

2.5 生成二維碼MyQR/mylibs/draw.py

使用?draw.py?畫出二維碼。

def draw_qrcode(abspath, qrmatrix):unit_len = 3 x = y = 4*unit_len pic = Image.new('1', [(len(qrmatrix)+8)*unit_len]*2, 'white') #新建一張白色的底圖 ''' 循環(huán)矩陣中的單位,在需要涂黑的單位啟用dra_a_black_unit()函數(shù)涂黑。 ''' for line in qrmatrix: for module in line: if module: draw_a_black_unit(pic, x, y, unit_len) #畫出黑單位 x += unit_len x, y = 4*unit_len, y+unit_len saving = os.path.join(abspath, 'qrcode.png') pic.save(saving) # 保存二維碼圖片 return saving

3.合并圖片的原理

讓我們來(lái)看一下?/MyQR/myqr.py?中的?combine()?方法,此方法調(diào)用了?Pillow?庫(kù)

讀取圖片操作

qr = Image.open(qr_name) #讀取二維碼圖片qr = qr.convert('RGBA') if colorized else qr #判斷二維碼是否有色 bg0 = Image.open(bg_name).convert('RGBA') #讀取要合并的圖片 bg0 = ImageEnhance.Contrast(bg0).enhance(contrast) # 調(diào)節(jié)對(duì)比度 bg0 = ImageEnhance.Brightness(bg0).enhance(brightness) # 調(diào)節(jié)亮度

將新加的圖片覆蓋原有的二維碼圖片,生成新的圖片并保存。

for i in range(qr.size[0]-24):for j in range(qr.size[1]-24): if not ((i in (18,19,20)) or (j in (18,19,20)) or (i<24 and j<24) or (i<24 and j>qr.size[1]-49) or (i>qr.size[0]-49 and j<24) or ((i,j) in aligs) or (i%3==1 and j%3==1) or (bg0.getpixel((i,j))[3]==0)): qr.putpixel((i+12,j+12), bg.getpixel((i,j)))

轉(zhuǎn)載于:https://www.cnblogs.com/leonchan/p/11546808.html

總結(jié)

以上是生活随笔為你收集整理的记-myqr流程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。