当前位置:网站首页>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)
边栏推荐
- Common authority query instructions in Oracle
- Go cache of go cache series
- Research Report on plastic antioxidant industry - market status analysis and development prospect forecast
- Research Report on micro gripper industry - market status analysis and development prospect prediction
- Longest public prefix of leetcode
- Basic knowledge of tree and binary tree (detailed illustration)
- China's crude oil heater market trend report, technological innovation and market forecast
- [use of pointer and pointer and array]
- beginning
- Analysis of enterprise financial statements [2]
猜你喜欢
Spend more time with your computer on this special holiday, HHH
Investment strategy analysis of China's electronic information manufacturing industry and forecast report on the demand outlook of the 14th five year plan 2022-2028 Edition
How to test the process of restoring backup files?
Browser - clean up the cache of JS in the page
[dynamic planning] p1220: interval DP: turn off the street lights
Gbase8s database type
kernel tty_ struct
[shutter] shutter layout component (physicalmodel component)
Baidu sued a company called "Ciba screen"
7. Build native development environment
随机推荐
Volvo's first MPV is exposed! Comfortable and safe, equipped with 2.0T plug-in mixing system, it is worth first-class
Browser - clean up the cache of JS in the page
Construction and maintenance of business websites [7]
MySQL learning record (6)
Analyze comp-206 advanced UNIX utils
Market trend report, technical dynamic innovation and market forecast of China's low gloss instrument
Chinese Indian seasoning market trend report, technical dynamic innovation and market forecast
PIP version update timeout - download using domestic image
Research Report on micro gripper industry - market status analysis and development prospect prediction
[shutter] statefulwidget component (image component | textfield component)
[shutter] statefulwidget component (bottom navigation bar component | bottomnavigationbar component | bottomnavigationbaritem component | tab switching)
MySQL learning record (7)
A river of spring water flows eastward
Add two numbers of leetcode
System (hierarchical) clustering method and SPSS implementation
Research Report on minimally invasive medical robot industry - market status analysis and development prospect prediction
[shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
Gbase 8s database basic syntax
[shutter] shutter layout component (Introduction to layout component | row component | column component | sizedbox component | clipoval component)
Research Report on market supply and demand and strategy of China's plastic trunking industry