Python 获取 exe 的 icon 并且保存
Python 获取 exe 的 icon 并且保存
参考链接:https://mail.python.org/pipermail/python-win32/2009-April/009078.html
import win32ui
import win32gui
import win32con
import win32api #ico_x = win32api.GetSystemMetrics(win32con.SM_CXICON)
#ico_y = win32api.GetSystemMetrics(win32con.SM_CYICON)
ico_x = 32
ico_y = 32 exePath = "c:/windows/system32/shell32.dll" large, small = win32gui.ExtractIconEx(exePath, 0)
useIcon = large[0]
destroyIcon = small[0]
win32gui.DestroyIcon(destroyIcon) hdc = win32ui.CreateDCFromHandle(win32gui.GetDC(0))
hbmp = win32ui.CreateBitmap()
hbmp.CreateCompatibleBitmap(hdc, ico_x, ico_x)
hdc = hdc.CreateCompatibleDC() hdc.SelectObject(hbmp)
hdc.DrawIcon(0,0), useIcon)
savePath = "d:/test.bmp"
hbmp.SaveBitmapFile(hdc, savePath)
注意:
win32gui.ExtractIconEx 只能提取32x32 和 16x16 的一大一小的图片
hbmp.SaveBitmapFile 只能在已经存在的路径下保存文件,如果路径不存在,用os.makedirs()创建 上面只是保存 bmp,如果想要保存 png,可以给 python 安装 Pillow模块,代码如下:
from PIL import Image
bmpstr = hbmp.GetBitmapBits(True)
img = Image.frombuffer(
'RGBA',
(32,32),
bmpstr, 'raw', 'BGRA', 0, 1
) img.save('icon.png')
Pillow 下载地址:https://pypi.org/project/Pillow/#files
Python 获取 exe 的 icon 并且保存的更多相关文章
- Python获取exe文件版本
import time, datetime, re, subprocess, sys, os, win32net, win32api, win32con, win32netcon, win32secu ...
- Python 获取 网卡 MAC 地址
/*********************************************************************** * Python 获取 网卡 MAC 地址 * 说明: ...
- Python打包EXE神器 pyinstaller
最近由于项目需要,以前的python文件需要编辑为EXE供前端客户使用. 由于最早接触的是distutils,所以一开始准备使用distutils和py2exe搭配来进行python的exe化,也就是 ...
- winform获取EXE图片
winform获取EXE图片 using (FileStream fs = new System.IO.FileStream(n, FileMode.OpenOrCreate, FileAccess. ...
- python获取指定目录下所有文件名os.walk和os.listdir
python获取指定目录下所有文件名os.walk和os.listdir 觉得有用的话,欢迎一起讨论相互学习~Follow Me os.walk 返回指定路径下所有文件和子文件夹中所有文件列表 其中文 ...
- Python获取路径下所有文件名
python 获取当前文件夹下所有文件名 os 模块下有两个函数: os.walk() os.listdir() 1 # -*- coding: utf-8 -*- 2 3 import os 4 ...
- python获取系统信息psutil
python获取系统信息psutil:psutil获取系统cpu使用率的方法是cpu_percent(),其有两个参数,分别是interval和percpu,interval指定的是计算cpu使用率的 ...
- bat wmic python 获取进程的所在路径
bat wmic python 获取进程的所在路径 doc: wmic process where name="process-name" get executablepath w ...
- Pyinstaller 打包python 到exe 在windows下免python环境运行python
在创建了独立应用(自包含该应用的依赖包)之后,还可以使用 PyInstaller 将 Python 程序生成可直接运行的程序,这个程序就可以被分发到对应的 Windows 或 Mac OS X 平台上 ...
随机推荐
- vc++中播放声音
http://www.cnblogs.com/xuemaxiongfeng/articles/2462560.html http://bbs.csdn.net/topics/390729457 htt ...
- Spring 控制器重定向
1.示例 return "redirect:/allUser"; redirect是跳转的意思后面是跳转的页面
- cpp调用c的动态库
目录 cpp调用c的动态库 title: cpp调用c的动态库 date: 2019/11/22 20:34:29 toc: true --- cpp调用c的动态库 CPP文件里这么引用头文件即可 e ...
- eNSP——配置通过FTP进行文件操作
原理: FTP (File Transfer Protocol,文件传输协议)是在TCP/IP网络和Internet.上最早使用的协议之-,在TCP/IP协议族中属于应用层协议,是文件传输的Inter ...
- 32.网络编程TCP/UDP服务
网络编程TCP: 服务器端口了解: port:0~65535 web服务:80 邮箱服务:556 0~1024:为服务默认的公认端口,一般我们不能用 套接字:socket socket作用 ip:po ...
- js模板(template.js)实现页面动态渲染
template.js是由纯JavaScript编写的第三方模板引擎.点击https://github.com/yanhaijing/template.js可进行下载. 在页头导入模板文件 <s ...
- 冲刺Noip2017模拟赛4 解题报告——五十岚芒果酱
题1 韬韬抢苹果(apple) [问题描述] 又到了收获的季节,树上结了许多韬韬,错了,是许多苹果,有很多个小韬韬都来摘苹 果.每个韬韬都想要最大的苹果,所以发生了争执,为了解决他们的矛盾,出题人定了 ...
- 冲刺Noip2017模拟赛3 解题报告——五十岚芒果酱
题1 素数 [问题描述] 给定一个正整数N,询问1到N中有多少个素数. [输入格式]primenum.in 一个正整数N. [输出格式]primenum.out 一个数Ans,表示1到N中有多少个素 ...
- HDU6582 Path【优先队列优化最短路 + dinic最大流 == 最小割】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6582 来源:2019 Multi-University Training Contest 1 题目大意 ...
- Date、DateFormat和Calendar类的简单认识
第三阶段 JAVA常见对象的学习 Date.DateFormat和Calendar类的简单认识 Date类 Date:表示特定的瞬间,精确到毫秒. (一) 构造方法: Date():根据当前的默认毫秒 ...