pythonctypes

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


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?

Edit: I'm using windows 10.


Solution

  • 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.

    Update: OP now mentions he can't use external libraries.

    Then you could virtually hit printscreen and read the clipboard. The code of PILLOW is open-source feel free to use it.

    Remember that you can always call a command from within python:

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

    Or download the zip of the library and import it in your code.