截屏然后blit它

时间:2017-12-15 11:01:53

标签: python image python-3.x pygame screenshot

有没有办法从GUI中使用pygame截取屏幕截图(前一帧的副本blitted),将其分配给表面变量并进行blit?没有将屏幕截图保存到文件,然后加载它,最后blitting它,

import pygame, os

pygame.init()
screen = pygame.display.set_mode((800, 400))

def TakeScreenShot(screen):
    pygame.image.save(screen, 'ScreenShot.png')
    pic = pygame.image.load(os.path.join('ScreenShot.png')).convert()

    return pic

pic = TakeScreenShot(screen)
screen.blit(pic, [0,0])
pygame.display.flip()

保存的屏幕截图然后加载似乎真的不必要......有没有一种方法可以绕过这个并直接将屏幕截图发送到GUI?

即,

import pygame, os

pygame.init()
screen = pygame.display.set_mode((800, 400))
pic = screen.getLastFrameBlitted()
screen.blit(pic, [0,0])
pygame.display.flip()

1 个答案:

答案 0 :(得分:4)

您可以随时获取屏幕副本并将其保存在变量中。

screen.blit(screenshot, (0, 0))

屏幕只是一个常规的Surface对象,可以这样对待。模仿屏幕截图照常完成

$ protoc --version
libprotoc 3.5.0
$ pip show protobuf
Name: protobuf
Version: 3.5.0.post1
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author: protobuf@googlegroups.com
Author-email: protobuf@googlegroups.com
License: 3-Clause BSD License
Location: {omitted}/venv/lib/python3.5/site-packages
Requires: six, setuptools