Example #1
0
def get_image(x=0, y=0, width=None, height=None):
    """
    Get an image from the screen.
    You can save the image like:

    image = get_image()
    image.save('screenshot.png', 'PNG')
    """

    # Get the dimensions
    window = get_window()
    if width is None:
        width = window.width - x
    if height is None:
        height = window.height - y

    # Create an image buffer
    image_buffer = (gl.GLubyte * (4 * width * height))(0)

    gl.glReadPixels(x, y, width, height, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE, image_buffer)
    image = PIL.Image.frombytes("RGBA", (width, height), image_buffer)
    image = PIL.ImageOps.flip(image)

    # image.save('glutout.png', 'PNG')
    return image
Example #2
0
def get_image(x: int = 0, y: int = 0, width: int = None, height: int = None):
    """
    Get an image from the screen.

    :param int x: Start (left) x location
    :param int y: Start (top) y location
    :param int width: Width of image. Leave blank for grabbing the 'rest' of the image
    :param int height: Height of image. Leave blank for grabbing the 'rest' of the image

    You can save the image like:

    .. highlight:: python
    .. code-block:: python

        image = get_image()
        image.save('screenshot.png', 'PNG')
    """

    # Get the dimensions
    window = get_window()
    if width is None:
        width = window.width - x
    if height is None:
        height = window.height - y

    # Create an image buffer
    image_buffer = (gl.GLubyte * (4 * width * height))(0)

    gl.glReadPixels(x, y, width, height, gl.GL_RGBA, gl.GL_UNSIGNED_BYTE,
                    image_buffer)
    image = PIL.Image.frombytes("RGBA", (width, height), image_buffer)
    image = PIL.ImageOps.flip(image)

    # image.save('glutout.png', 'PNG')
    return image
Example #3
0
 def on_key_press(self, key):
     factory = GameFactory()
     fight_view = factory.create_fightview()
     fight_view.setup()
     window = window_commands.get_window()
     window.show_view(fight_view)