当前位置:网站首页>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)
边栏推荐
- 7. Build native development environment
- MySQL learning record (9)
- [CV] Wu Enda machine learning course notes | Chapter 12
- 如何防止你的 jar 被反编译?
- China plastic bottle and container market trend report, technological innovation and market forecast
- Adding data to the head or tail of the rar file can still decompress normally
- Report on investment development and strategic recommendations of China's vibration isolator market, 2022-2027
- Sword finger offer (II) -- search in two-dimensional array
- Accounting regulations and professional ethics [18]
- Research Report on minimally invasive medical robot industry - market status analysis and development prospect prediction
猜你喜欢

Huawei Hongmeng watch achieves fireworks display effect on New Year's Eve

PIP version update timeout - download using domestic image

Check the confession items of 6 yyds

MySQL learning record (6)

Redis分布式锁故障,我忍不住想爆粗...

Analysis of neural network

Research Report on ranking analysis and investment strategic planning of RFID market competitiveness of China's industrial manufacturing 2022-2028 Edition
![[shutter] shutter layout component (physicalmodel component)](/img/6a/f8161fb7c8e9012456622f1920da64.gif)
[shutter] shutter layout component (physicalmodel component)
![[CV] Wu Enda machine learning course notes | Chapter 12](/img/c8/9127683b6c101db963edf752ffda86.jpg)
[CV] Wu Enda machine learning course notes | Chapter 12

MySQL learning record (7)
随机推荐
1005 spell it right (20 points) "PTA class a exercise"
The web version of xshell supports FTP connection and SFTP connection
How is LinkedList added?
MySQL learning record (2)
Unexpectedly, there are such sand sculpture code comments! I laughed
Golang string segmentation
[12] the water of the waves is clear, which can wash my tassel. The water of the waves is muddy, which can wash my feet
MySQL learning record (4)
Spend more time with your computer on this special holiday, HHH
Construction and maintenance of business website [3]
7. Build native development environment
Chinese Indian seasoning market trend report, technical dynamic innovation and market forecast
Research Report on market supply and demand and strategy of microplate instrument industry in China
2021 software security report: open source code, happiness and disaster depend on each other?
Go web programming practice (1) -- basic syntax of go language
MySQL learning record (1)
China's log saw blade market trend report, technological innovation and market forecast
Research Report on plastic antioxidant industry - market status analysis and development prospect forecast
Common routines of compressed packets in CTF
[shutter] the shutter plug-in is used in the shutter project (shutter plug-in management platform | search shutter plug-in | install shutter plug-in | use shutter plug-in)