簡體   English   中英

截取完整的python屏幕截圖

[英]take full screenshot python

我正在嘗試為我的屏幕截圖。

我知道這個功能

pyautogui.screenshot() 

此功能的問題在於它只能截取一個屏幕的屏幕截圖。 我正在嘗試為所有可用屏幕(通常是兩個)截取完整屏幕截圖。 但是,它似乎在這方面不起作用。

鑒於您想使用 Windows 系統,我建議您使用 Python 庫Desktopmagic

下面是一個例子:

from __future__ import print_function

from desktopmagic.screengrab_win32 import (
getDisplayRects, saveScreenToBmp, saveRectToBmp, getScreenAsImage,
getRectAsImage, getDisplaysAsImages)

# Save the entire virtual screen as a BMP (no PIL required)
saveScreenToBmp('screencapture_entire.bmp')

# Save an arbitrary rectangle of the virtual screen as a BMP (no PIL required)
saveRectToBmp('screencapture_256_256.bmp', rect=(0, 0, 256, 256))

# Save the entire virtual screen as a PNG
entireScreen = getScreenAsImage()
entireScreen.save('screencapture_entire.png', format='png')

# Get bounding rectangles for all displays, in display order
print("Display rects are:", getDisplayRects())
# -> something like [(0, 0, 1280, 1024), (-1280, 0, 0, 1024), (1280, -176, 3200, 1024)]

# Capture an arbitrary rectangle of the virtual screen: (left, top, right, bottom)
rect256 = getRectAsImage((0, 0, 256, 256))
rect256.save('screencapture_256_256.png', format='png')

# Unsynchronized capture, one display at a time.
# If you need all displays, use getDisplaysAsImages() instead.
for displayNumber, rect in enumerate(getDisplayRects(), 1):
imDisplay = getRectAsImage(rect)
imDisplay.save('screencapture_unsync_display_%d.png' % (displayNumber,), format='png')

# Synchronized capture, entire virtual screen at once, cropped to one Image per display.
for displayNumber, im in enumerate(getDisplaysAsImages(), 1):
im.save('screencapture_sync_display_%d.png' % (displayNumber,), format='png')

如果您介意,我會建議另一個模塊: MSS (您不需要 PIL 或任何其他模塊,只需 Python;它是跨平台的):

from mss import mss

with mss() as sct:
    sct.shot(mon=-1, output="fullscreen.png")

如果您有興趣,文檔會嘗試解釋更多內容。

使用 pyscreenshot 庫對我有用,我截取了所有屏幕的屏幕截圖。

來源: https : //pypi.org/project/pyscreenshot/

#-- include('examples/showgrabfullscreen.py') --#
import pyscreenshot as ImageGrab

if __name__ == '__main__':

    # grab fullscreen
    im = ImageGrab.grab()

    # save image file
    im.save('screenshot.png')

    # show image in a window
    im.show()
#-#

如果您不想打開 GUI,只需注釋im.show()行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM