Because in one of my programs want to add a feature, today to see how to use Python, functional implementation is very simple, directly on the code
From PIL import Imagegrab
im = Imagegrab.grab ()
Im.save (addr, ' jpeg ')
A few lines of code to implement the function I want, PIL (Python Image library) is a Python graphics library, the need to download the installation itself, Im = Imagegrab.grab () This line of code implementation function, can take parameters, specify the coordinates of the picture to be captured location , the default full screen without parameters, Im.save (addr, ' jpeg ') is to save the captured picture, the first parameter is the save path, the second parameter is the picture format
#-*-coding:cp936-*-ImportTime,imageImportOS, Win32gui, Win32ui, Win32con, Win32APIdefwindow_capture (dpath):" ""screenshot function, call method Window_capture (' d:\\ '), parameter for the specified saved directory return picture file name, file name format: date. jpg: 2009328224853.jpg" "hwnd=0 HWNDDC=Win32gui. GETWINDOWDC (HWND) MFCDC=Win32ui. Createdcfromhandle (HWNDDC) SaveDC=Mfcdc.createcompatibledc () Savebitmap=Win32ui. CreateBitmap () Moniterdev=Win32API. Enumdisplaymonitors (none,none) W= Moniterdev[0][2][2] H= Moniterdev[0][2][3] #Print W,h #图片大小Savebitmap.createcompatiblebitmap (MFCDC, W, h) savedc.selectobject (Savebitmap) Savedc.bitblt ((0,0), (W, h), MF CDC, (0,0), Win32con. srccopy) cc=time.gmtime () bmpname=str (Cc[0]) +str (cc[1]) +str (cc[2]) +str (cc[3]+8) +str (cc[4]) +str (cc[5]) +'. bmp'savebitmap.savebitmapfile (SaveDC, Bmpname) Image.open (bmpname). Save (bmpname[:-4]+". jpg") Os.remove (bmpname) jpgname=bmpname[:-4]+'. jpg'Djpgname=dpath+jpgname Copy_command="Move%s%s"%(Jpgname, Djpgname) Os.popen (Copy_command)returnbmpname[:-4]+'. jpg'#Call the screenshot functionWindow_capture ('d:\\')
Python implementation screen