当前位置:网站首页>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)
边栏推荐
- Jar package startup failed -mysql modify the default port number / set password free enter
- 如何防止你的 jar 被反编译?
- Send blessings on Lantern Festival | limited edition red envelope cover of audio and video is released!
- [shutter] statefulwidget component (floatingactionbutton component | refreshindicator component)
- Download vagrant box file locally from Atlas and configuring it
- Baidu sued a company called "Ciba screen"
- China's noise meter market trend report, technical dynamic innovation and market forecast
- 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
- Construction and maintenance of business websites [7]
- Hot backup routing protocol (HSRP)
猜你喜欢

5 environment construction spark on yarn

Unexpectedly, there are such sand sculpture code comments! I laughed
![[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)](/img/5f/e96baefd9481c496024fed345e31fe.jpg)
[shutter] shutter layout component (fractionallysizedbox component | stack layout component | positioned component)

26 FPS video super-resolution model DAP! Output 720p Video Online

读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...

MySQL learning record (4)

treevalue——Master Nested Data Like Tensor

Common routines of compressed packets in CTF

Hot backup routing protocol (HSRP)

MySQL learning record (6)
随机推荐
Construction and maintenance of business websites [6]
Accounting regulations and professional ethics [16]
MySQL learning record (7)
Analysis of enterprise financial statements [2]
When Valentine's Day falls on Monday
Free open source web version of xshell [congratulations on a happy new year]
Lantern Festival, come and guess lantern riddles to win the "year of the tiger Doll"!
How is LinkedList added?
Share the easy-to-use fastadmin open source system - Installation
Record the problems encountered by nodejs asynchronism
26 FPS video super-resolution model DAP! Output 720p Video Online
[dynamic planning] p1220: interval DP: turn off the street lights
kernel_ uaf
China plastic box market trend report, technological innovation and market forecast
读博士吧,研究奶牛的那种!鲁汶大学 Livestock Technology 组博士招生,牛奶质量监测...
2021 v+ Quanzhen internet global innovation and Entrepreneurship Challenge, one of the top ten audio and video scene innovation and application pioneers
Redis分布式锁故障,我忍不住想爆粗...
Cardinality sorting (detailed illustration)
Spend more time with your computer on this special holiday, HHH
Construction and maintenance of business websites [10]