Python win32api提取exe表徵圖icon

來源:互聯網
上載者:User

標籤:

 

轉載地址: http://blog.csdn.net/gumanren/article/details/6129416

 

代碼如下:

 1 # -*- coding: utf-8 -*-   2 import sys 3 import win32ui 4 import win32gui 5 from PyQt4 import QtCore 6 from PyQt4 import QtGui 7 class testWindow(QtGui.QMainWindow): 8     def __init__(self): 9         super(testWindow, self).__init__()10         self.setGeometry(180.0, 130.0, 280.0, 200.0)11         self.setMouseTracking(True)12         large, small = win32gui.ExtractIconEx(r"netbeans.exe", 0)13         win32gui.DestroyIcon(small[0])14         self.pixmap = QtGui.QPixmap.fromWinHBITMAP(self.bitmapFromHIcon(large[0]), 2)15         16         self.pixmap.save("a.ico","ico")17         18     def bitmapFromHIcon(self, hIcon):19         hdc = win32ui.CreateDCFromHandle(win32gui.GetDC(0))20         hbmp = win32ui.CreateBitmap()21         hbmp.CreateCompatibleBitmap(hdc, 32, 32)22         hdc = hdc.CreateCompatibleDC()23         hdc.SelectObject(hbmp)24         hdc.DrawIcon((0, 0), hIcon)25         hdc.DeleteDC()26         return hbmp.GetHandle()27     # paintevent事件28     def paintEvent(self, event):29         # palette 調色盤多個pix顯示,   30         painter = QtGui.QPainter()31         palette = QtGui.QPalette()32         palette.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap(self.pixmap)))   # 設定背景圖片33         self.setPalette(palette)34         #painter繪圖類只顯示一個35         #painter.begin(self)36         #painter.setRenderHint(QtGui.QPainter.Antialiasing)37         #painter.setPen(QtCore.Qt.NoPen)38         #painter.setBrush(QtGui.QBrush(QtGui.QColor(255.0, 255.0, 255.0, 255.0), QtCore.Qt.SolidPattern))39         #painter.drawRect(QtCore.QRect(0.0, 0.0, 280.0, 400.0))40         #painter.drawPixmap(QtCore.QRect(0.0, 0.0, 32.0, 32.0), self.pixmap)41         #painter.end()42 if __name__ == "__main__":43     app = QtGui.QApplication(sys.argv)44     mainWindow = testWindow()45     mainWindow.show()46     app.exec_()

 

顯示效果:

 

Python win32api提取exe表徵圖icon

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.