Python implementation Screen capture

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.