有没有办法用 ctypes 在 python 中捕获屏幕图像?

Is there a way to capture an image of the screen in python with ctypes?

我想让 python 将整个屏幕的图像文件保存为带有 ctypes 的变量,这样我就可以在程序中访问屏幕并对其进行一些操作(比如将其放在 pygame window)。我不能使用任何其他库,除非它们包含在 python 中(无需安装或 pip)。有人知道怎么做吗?

编辑:我正在使用 windows 10.

PIL.ImageGrab 来自 PILLOW(一个 python 图像库分支,您可以使用 pip 安装)。您可以给出边界框或捕获整个屏幕。

更新: OP 现在提到他不能使用外部库。

那么你可以virtually hit printscreen and read the clipboard。 PILLOW的代码是开源的,大家可以放心使用。

请记住,您可以随时 call a command from within python:

>>> import os
>>> os.system("pip install pillow")

或者下载库的 zip 并将其导入到您的代码中。