我目前从网上截取了一个片段,可以用相机拍摄 4 张照片。这很好用。
然后,我尝试从网络上删除另一个片段,该片段会在拍照之前倒计时,这让我非常头疼,我想知道是否有更聪明的人可以为我解决这个问题......
surface = pygame.display.set_mode((0,0))
fontObj = pygame.font.Font("freesansbold.ttf", 100)
textSurfaceObj = fontObj.render("3", True, (255, 0, 0))
textRectObj = textSurfaceObj.get_rect()
textRectObj.center = (surface.get_width() / 2, surface.get_height() / 2)
def show_image(image_path):
screen = init_pygame()
img=pygame.image.load(image_path)
img = pygame.transform.scale(img,(transform_x,transfrom_y))
screen.blit(img,(offset_x,offset_y))
pygame.display.flip()
def init_pygame():
pygame.init()
size = (pygame.display.Info().current_w, pygame.display.Info().current_h)
pygame.display.set_caption('Pictures')
pygame.mouse.set_visible(False) #hide the mouse cursor
return pygame.display.set_mode(size, pygame.FULLSCREEN)
print "Taking pics"
now = time.strftime("%Y-%m-%d-%H:%M:%S")
try:
for i, filename in enumerate(camera.capture_continuous(config.file_path + now + '-' + '{counter:02d}.jpg')):
print(filename)
for y in range(3,0,-1):
surface.fill((0,0,0,0))
textSurfaceObj = fontObj.render(str(y), True, (255, 0, 0))
surface.blit(textSurfaceObj, textRectObj)
pygame.display.update()
pygame.time.wait(1000)
sleep(capture_delay)
if i == total_pics-1:
break
finally:
camera.stop_preview()
camera.close()
它返回给我:
Traceback (most recent call last):
File "pics.py", line 58, in <module>
fontObj = pygame.font.Font("freesansbold.ttf", 100)
pygame.error: font not initialized
我的印象是,如果 pygame.init() 完成,字体应该被初始化?