Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
553 views
in Technique[技术] by (71.8m points)

image - Python Imaging Library fails to grab whole screen

I am using PIL to grab a screen shot, but it is only capturing a part of the screen.

Here is a screen shot of my desktop

And this is what the program captures

As you can see, the screen has a good amount of space chopped off on the side and along the bottom. I tried to correct this by adjusting the size of the capture zone, but that just resulted in the extra areas just to be filled with black

I'm thinking that there is a limit to the maximum resolution that the library can capture, but I cant really find any documentation saying so.

Below is my code

import ImageGrab
import os
import time


def screenGrab():
    box = (0, 0, 1920, 1080)
    im = ImageGrab.grab(box)
    im.save(os.getcwd() + '\screenshot_' + str(int(time.time())) + '.png', 'PNG')


def main():
    screenGrab()

if __name__ == '__main__':
    main()

Dose anyone know how to fix this issue or know why its happening?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is a working workaround for this without fiddling with the OS settings. The solution is to use the following to make your program DPI aware on Windows :

from ctypes import windll
user32 = windll.user32
user32.SetProcessDPIAware()

Hope that helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...