当前位置:网站首页>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 [2]
- Construction and maintenance of business websites [10]
- Report on investment development and strategic recommendations of China's vibration isolator market, 2022-2027
- Market trend report, technical dynamic innovation and market forecast of China's low gloss instrument
- The web version of xshell supports FTP connection and SFTP connection
- Today, I met a Alipay and took out 35K. It's really sandpaper to wipe my ass. it's a show for me
- [shutter] statefulwidget component (pageview component)
- How is LinkedList added?
- Go language learning summary (5) -- Summary of go learning notes
- [shutter] shutter layout component (opacity component | clipprect component | padding component)
猜你喜欢
6 pyspark Library
Redis分布式锁故障,我忍不住想爆粗...
MySQL learning record (2)
[shutter] statefulwidget component (image component | textfield component)
[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)
26 FPS video super-resolution model DAP! Output 720p Video Online
发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
Welfare, let me introduce you to someone
Share the easy-to-use fastadmin open source system - Installation
Spend more time with your computer on this special holiday, HHH
随机推荐
How is LinkedList added?
[shutter] statefulwidget component (pageview component)
kernel_ uaf
China's Micro SD market trend report, technology dynamic innovation and market forecast
Add two numbers of leetcode
Download vagrant box file locally from Atlas and configuring it
[shutter] shutter layout component (opacity component | clipprect component | padding component)
Go web programming practice (1) -- basic syntax of go language
Internal/validators js:124 throw new ERR_ INVALID_ ARG_ Type (name, 'string', value) -- solution
发现你看不到的物体!南开&武大&ETH提出用于伪装目标检测SINet,代码已开源!...
Get weekday / day of week for datetime column of dataframe - get weekday / day of week for datetime column of dataframe
Redis分布式锁故障,我忍不住想爆粗...
Redis -- three special data types
Research Report on market supply and demand and strategy of China's plastic trunking industry
Cloud computing technology [2]
Makefile: usage of control functions (error, warning, info)
Internet Explorer ignores cookies on some domains (cannot read or set cookies)
Adding data to the head or tail of the rar file can still decompress normally
The web version of xshell supports FTP connection and SFTP connection
What is the difference between programming in real work and that in school?