当前位置:网站首页>Pyqt picture decodes and encodes and loads pictures
Pyqt picture decodes and encodes and loads pictures
2022-07-02 21:39:00 【Wei Wei】
Here's the catalog title
Picture decoding base64
First pass the picture through base64, Decode into bytecode ;
def pictopy(picture_names, py_name):
""" Convert the image file to py file :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()
# Pay attention to this side b64str We must add .decode()
write_data.append('%s = "%s"\n' % (filename, b64str.decode()))
# Save the decoded picture bytecode as .py file
f = open('%s.py' % py_name, 'w+')
for data in write_data:
f.write(data)
f.close()
code
Bytecode warp base64 code ,
def get_pic(pic_code, pic_name):
image = open(pic_name, 'wb')
image.write(base64.b64decode(pic_code))
image.close()
label Loading pictures
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)
Example
if __name__ == '__main__':
pics = ["qq.gif", " Sit down .gif", " Sit up .gif", " walk .gif"]
pictopy(pics, 'memory_pic') # take pics The picture inside says memory_pic.py in
print("ok")
get_pic_decode(qq_gif)
边栏推荐
- Construction and maintenance of business website [3]
- D4: unpaired image defogging, self enhancement method based on density and depth decomposition (CVPR 2022)
- Redis分布式锁故障,我忍不住想爆粗...
- Go web programming practice (2) -- process control statement
- Market trend report, technical dynamic innovation and market forecast of China's low gloss instrument
- What is the difference between programming in real work and that in school?
- treevalue——Master Nested Data Like Tensor
- Detailed explanation of OSI seven layer model
- Micro SD Card Industry Research Report - market status analysis and development prospect forecast
- [dynamic planning] p1220: interval DP: turn off the street lights
猜你喜欢
5 environment construction spark on yarn
[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)
Spend more time with your computer on this special holiday, HHH
The neo4j skill tree was officially released to help you easily master the neo4j map database
[shutter] shutter layout component (physicalmodel component)
[Yu Yue education] reference materials of analog electronic technology of Nanjing Institute of information technology
Basic IO interface technology - microcomputer Chapter 7 Notes
MySQL learning record (3)
kernel tty_ struct
Welfare, let me introduce you to someone
随机推荐
Lantern Festival, come and guess lantern riddles to win the "year of the tiger Doll"!
How is LinkedList added?
Capacity expansion mechanism of ArrayList
What is the difference between programming in real work and that in school?
MySQL learning record (5)
Redis分布式锁故障,我忍不住想爆粗...
Construction and maintenance of business websites [10]
Huawei Hongmeng watch achieves fireworks display effect on New Year's Eve
China plastic bottle and container market trend report, technological innovation and market forecast
China's Micro SD market trend report, technology dynamic innovation and market forecast
Unexpectedly, there are such sand sculpture code comments! I laughed
AES encryption CBC mode pkcs7padding filling Base64 encoding key 32byte iv16byte
Construction and maintenance of business websites [9]
[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)
Research Report on ranking analysis and investment strategic planning of RFID market competitiveness of China's industrial manufacturing 2022-2028 Edition
Chinese Indian seasoning market trend report, technical dynamic innovation and market forecast
Accounting regulations and professional ethics [18]
Import a large amount of data to redis in shell mode
Read a doctor, the kind that studies cows! Dr. enrollment of livestock technology group of Leuven University, milk quality monitoring
Research Report on crude oil tanker industry - market status analysis and development prospect forecast