資源簡介
python 截圖 抓圖 源碼,支持快捷鍵截屏,自動保存,源碼自由修改

代碼片段和文件信息
#!/usr/bin/env?python
#coding=gb2312
#此模塊主要提供抓圖功能,支持以下三種抓圖方式:
#1、抓取全屏快捷鍵CTRL+F1
#2、抓取當前窗口,快捷鍵CTRL+F2
#3、抓取所選區域,快捷鍵CTRL+F3
#抓到之后,會自動彈出保存對話框,選擇路徑保存即可
#*******************************************
#更新記錄
#0.1?2012-03-10?create?by?dyx1024
#********************************************
import?pyhk
import?wx
import?os
import?sys
from?PIL?import?ImageGrab
import?ctypes
import?win32gui
import?ctypes.wintypes?
import?screen_tray
def?capture_fullscreen(SysTrayIcon):
????‘‘‘
????Function:全屏抓圖
????Input:NONE
????Output:?NONE
????author:?socrates
????blog:http://blog.csdn.net/dyx1024
????date:2012-03-10
????‘‘‘??
????#抓圖???
????pic?=?ImageGrab.grab()
????
????#保存圖片
????save_pic(pic)
????
def?capture_current_windows(SysTrayIcon?=?None):
????‘‘‘
????Function:抓取當前窗口
????Input:NONE
????Output:?NONE
????author:?socrates
????blog:http://blog.csdn.net/dyx1024
????date:2012-03-10
????‘‘‘?
????#窗口結構???????
????class?RECT(ctypes.Structure):
????????_fields_?=?[(‘left‘?ctypes.c_long)
????????????????(‘top‘?ctypes.c_long)
????????????????(‘right‘?ctypes.c_long)
????????????????(‘bottom‘?ctypes.c_long)]
????????def?__str__(self):
????????????return?str((self.left?self.top?self.right?self.bottom))
????
????rect?=?RECT()
????
????#獲取當前窗口句柄
????HWND?=?win32gui.GetForegroundWindow()
????
????#取當前窗口坐標
????ctypes.windll.user32.GetWindowRect(HWNDctypes.byref(rect))
????#調整坐標
????rangle?=?(rect.left+2rect.top+2rect.right-2rect.bottom-2)
????
????#抓圖
????pic?=?ImageGrab.grab(rangle)
????
????#保存
????save_pic(pic)
????
def?capture_choose_windows(SysTrayIcon):
????‘‘‘
????Function:抓取選擇的區域,沒有自己寫這個,借用QQ抓圖功能
????Input:NONE
????Output:?NONE
????author:?socrates
????blog:http://blog.csdn.net/dyx1024
????date:2012-03-10
????‘‘‘?????
????try:
?????????#加載QQ抓圖使用的dll
?????????dll_handle?=?ctypes.cdll.LoadLibrary(‘CameraDll.dll‘)?
????except?Exception:
?????????????try:
?????????????????#如果dll加載失敗,則換種方法使用,直接運行,如果還失敗,退出
?????????????????os.system(“Rundll32.exe?CameraDll.dll?CameraSubArea“)
?????????????except?Exception:
?????????????????return????
????else:
?????????try:
?????????????#加載dll成功,則調用抓圖函數,注:沒有分析清楚這個函數帶的參數個數
?????????????#及類型,所以此語句執行后會報參數缺少4個字節,但不影響抓圖功能,所
?????????????#以直接忽略了些異常
?????????????dll_handle.CameraSubArea(0)
?????????except?Exception:
?????????????return???????????
def?save_pic(pic?filename?=?‘未命令圖片.png‘):
????‘‘‘
????Function:使用文件對框,保存圖片
????Input:NONE
????Output:?NONE
????author:?socrates
????blog:http://blog.csdn.net/dyx1024
????date:2012-03-10
????‘‘‘?????
????app?=?wx.PySimpleApp()
????
????wildcard?=?“PNG(*.png)|*.png“
????dialog?=?wx.FileDialog(None?“Select?a?place“?os.getcwd()
???????????????????????????filename?wildcard?wx.SAVE)
????if?dialog.ShowModal()?==?wx.ID_OK:
????????pic.save(dialog.GetPath().encode(‘gb2312‘))
????else:
????????pass
????
????dialog.Destroy()????
?
class?hook_kev_screenshot:
????def?__init__(se
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????544768??2010-09-15?16:29??python多功能抓圖源碼\代碼\CameraDll.dll
?????文件???????4284??2012-04-07?14:21??python多功能抓圖源碼\代碼\screenshot.py
?????文件???????9662??2012-04-07?15:02??python多功能抓圖源碼\代碼\screenshot_tray.ico
?????文件??????11459??2012-04-07?16:10??python多功能抓圖源碼\代碼\screen_tray.py
?????文件?????544768??2010-09-15?16:29??python多功能抓圖源碼\執行\CameraDll.dll
?????文件???????9662??2012-04-07?15:02??python多功能抓圖源碼\執行\datafile\screenshot.ico
?????文件????9766431??2012-04-07?16:11??python多功能抓圖源碼\執行\screen_tray.exe
?????目錄??????????0??2019-01-09?10:44??python多功能抓圖源碼\執行\datafile
?????目錄??????????0??2012-04-07?18:29??python多功能抓圖源碼\代碼
?????目錄??????????0??2017-10-31?14:58??python多功能抓圖源碼\執行
?????目錄??????????0??2019-01-09?10:44??python多功能抓圖源碼
-----------?---------??----------?-----??----
?????????????10891034????????????????????11
評論
共有 條評論