有没有办法用ctypes在python中捕获屏幕图像? [英] Is there a way to capture an image of the screen in python with ctypes?
问题描述
我想让python将整个屏幕的图像文件另存为带有ctypes的变量,以便我可以在程序中访问屏幕并对其进行处理(例如将其放在pygame窗口中)。我无法使用任何其他库,除非它们包含在python中(没有安装或pip)。有人知道怎么做吗?
I want to have python save an image file of the whole screen as a variable with ctypes so that I could access the screen in a program and do something with it (like put it on a pygame window). I can't use any other libraries unless they are included with python (no installing or pip). Does anyone know how to do this?
编辑:我正在使用Windows 10。
I'm using windows 10.
推荐答案
PIL.ImageGrab 来自PILLOW(可通过pip安装的python图像库fork)。您可以给定边界框或捕获整个屏幕。
PIL.ImageGrab is from PILLOW (a python image library fork which you can install with pip). You can give a bounding box or capture the entire screen.
更新: OP现在提到他不能使用外部库。
Update: OP now mentions he can't use external libraries.
然后,您可以实际上已打到打印屏幕和阅读剪贴板一个>。 PILLOW的代码是开源的,随时可以使用。
Then you could virtually hit printscreen and read the clipboard. The code of PILLOW is open-source feel free to use it.
请记住,您始终可以从python内部调用命令:
>>> import os
>>> os.system("pip install pillow")
或下载该库的zip并将其导入您的代码。
Or download the zip of the library and import it in your code.
这篇关于有没有办法用ctypes在python中捕获屏幕图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!