赞
踩
第一种方式
1、用base64 将图片编码 和 解码
副作用:需要生成一个文件夹 存储图片。或者开启的瞬间 删除该文件与内容
(1)如下图,将图片转成字符串,存储起来
- import base64
-
- url4 ="./icon/xxx.png"
-
- f = open(url4, 'rb')
- img = base64.b64encode(f.read())
- print(img)
(2)将字符串再转成图片,调用该图片
- path='./image'
- if(os.path.exists(path)):
- pass
- else:
- os.mkdir(path)
-
- f = open('./image/one.png', 'wb') # 将要保存的文件名与路径
- f.write(base64.b64decode(img1)) ##需要解码的图片,写入文件中去。
- f.close()
第二种方式
(1)新建images.qrc ,内容如下
- <RCC>
- <qresource prefix="/">
- <file>icon/xxx.png</file>
- <file>icon/xxx.png</file>>
- <file>icon/xxx.png</file>>
- <file>icon/xxx.png</file>>
- <file>icon/xxx.png</file>>
- </qresource>
- </RCC>
(2)cmd该路径下运行 : PyRcc5 -o images.py images.qrc
(3)文件夹下会生成 images.py文件,若需要引用png,
(1 路径写法 (:/icon/xxx.png)
(2 import images导入 图片
最后使用pyinstaller 打包 :pyinstaller -F -w -i icon.ico Main.py
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。