当前位置:网站首页>pyqt图片解码 编码后加载图片
pyqt图片解码 编码后加载图片
2022-07-02 21:32:00 【威唯】
这里写目录标题
图片解码base64
先将图片经base64,解码成字节码;
def pictopy(picture_names, py_name):
""" 将图像文件转换为py文件 :param picture_name: """
write_data = []
for picture_name in picture_names:
filename = picture_name.replace('.', '_')
open_pic = open("%s" % picture_name, 'rb')
b64str = base64.b64encode(open_pic.read())
open_pic.close()
# 注意这边b64str一定要加上.decode()
write_data.append('%s = "%s"\n' % (filename, b64str.decode()))
#将解码后的图片字节码保存成 .py文件
f = open('%s.py' % py_name, 'w+')
for data in write_data:
f.write(data)
f.close()
编码
字节码经base64编码,
def get_pic(pic_code, pic_name):
image = open(pic_name, 'wb')
image.write(base64.b64decode(pic_code))
image.close()
label 加载图片
def get_pic_decode(self, pic_code):
img_b64decode = base64.b64decode(pic_code)
img_io = io.BytesIO(img_b64decode)
img = Image.open(img_io)
pix = img.toqpixmap()
self.gif_label.setPixmap(pix)
self.gif_label.setScaledContents(True)
示例
if __name__ == '__main__':
pics = ["qq.gif", "坐下.gif", "坐起.gif", "行走.gif"]
pictopy(pics, 'memory_pic') # 将pics里面的图片写到 memory_pic.py 中
print("ok")
get_pic_decode(qq_gif)
边栏推荐
- beginning
- Accounting regulations and professional ethics [19]
- Cloud computing technology [1]
- MySQL learning record (1)
- Send blessings on Lantern Festival | limited edition red envelope cover of audio and video is released!
- Research Report on market supply and demand and strategy of microplate instrument industry in China
- Gbase 8s database basic syntax
- D4:非成对图像去雾,基于密度与深度分解的自增强方法(CVPR 2022)
- Construction and maintenance of business websites [10]
- Research Report on market supply and demand and strategy of China's atomic spectrometer industry
猜你喜欢
MySQL learning record (6)
In depth research and investment feasibility report of global and Chinese isolator industry, 2022-2028
MySQL learning record (5)
26 FPS video super-resolution model DAP! Output 720p Video Online
[hands on deep learning]02 softmax regression
[shutter] statefulwidget component (image component | textfield component)
The neo4j skill tree was officially released to help you easily master the neo4j map database
Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
[fluent] dart technique (independent main function entry | nullable type determination | default value setting)
Gbase8s database type
随机推荐
Redis分布式锁故障,我忍不住想爆粗...
Go language learning summary (5) -- Summary of go learning notes
Construction and maintenance of business websites [7]
Welfare | Pu Aries | liv heart co branded Plush surrounding new products are on the market!
Detailed explanation of OSI seven layer model
Add two numbers of leetcode
Construction and maintenance of business websites [8]
Jar package startup failed -mysql modify the default port number / set password free enter
2021 software security report: open source code, happiness and disaster depend on each other?
In depth research and investment feasibility report of global and Chinese isolator industry, 2022-2028
1005 spell it right (20 points) "PTA class a exercise"
[shutter] statefulwidget component (image component | textfield component)
Cloud computing technology [1]
3DES (deSede) encryption CBC mode pkcs7padding filling Base64 encoding key 24byte iv8byte
Research Report on micro vacuum pump industry - market status analysis and development prospect prediction
MySQL inserts Chinese data and reports an error. Set the default collation
Interpretation of some papers published by Tencent multimedia laboratory in 2021
如何防止你的 jar 被反编译?
When Valentine's Day falls on Monday
[shutter] shutter layout component (Introduction to layout component | row component | column component | sizedbox component | clipoval component)