如何使用 pygame.camera 重新缩放摄像机镜头
How to re-scale camera footage using pygame.camera
嘿,有谁知道如何重新缩放 pygame 摄像机镜头我到处都看过,但似乎没有任何方法可以做到这一点。我试过使用 pygame.transform.scale
但 pygame 屏幕甚至没有弹出
代码:
import pygame
from pygame.locals import *
import time
import pygame.camera
import pygame.image
pygame.init()
pygame.camera.init()
pygame.display.set_caption("Game")
cameras = pygame.camera.list_cameras()
print("Using camera %s ..." % cameras[0])
cam1 = pygame.camera.Camera(cameras[0])
cam1.start()
img1 = cam1.get_image()
flags = DOUBLEBUF
screen = pygame.display.set_mode((100,100), flags, 4)
while 1:
for event in pygame.event.get():
pygame.event.set_allowed(KEYDOWN)
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
pygame.quit()
pygame.camera.quit()
img1 = cam1.get_image().convert()
scaled_img1 = pygame.transform.scale(img1, (500, 500))
screen.blit(scaled_img1, (0, 0))
pygame.display.update()
pygame.transform.scale
不缩放 Surface 本身,而是 returns 一个新缩放的 Surface:
scaled_img1 = pygame.transform.scale(img1, (100, 100))
另见 and 。
此外,您必须 blit
缩放图像后的图像:
while 1:
# [...]
scaled_img1 = pygame.transform.scale(img1, (100, 100))
screen.blit(scaled_img1 , (0, 0))
pygame.display.update()
嘿,有谁知道如何重新缩放 pygame 摄像机镜头我到处都看过,但似乎没有任何方法可以做到这一点。我试过使用 pygame.transform.scale
但 pygame 屏幕甚至没有弹出
代码:
import pygame
from pygame.locals import *
import time
import pygame.camera
import pygame.image
pygame.init()
pygame.camera.init()
pygame.display.set_caption("Game")
cameras = pygame.camera.list_cameras()
print("Using camera %s ..." % cameras[0])
cam1 = pygame.camera.Camera(cameras[0])
cam1.start()
img1 = cam1.get_image()
flags = DOUBLEBUF
screen = pygame.display.set_mode((100,100), flags, 4)
while 1:
for event in pygame.event.get():
pygame.event.set_allowed(KEYDOWN)
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
pygame.quit()
pygame.camera.quit()
img1 = cam1.get_image().convert()
scaled_img1 = pygame.transform.scale(img1, (500, 500))
screen.blit(scaled_img1, (0, 0))
pygame.display.update()
pygame.transform.scale
不缩放 Surface 本身,而是 returns 一个新缩放的 Surface:
scaled_img1 = pygame.transform.scale(img1, (100, 100))
另见
此外,您必须 blit
缩放图像后的图像:
while 1:
# [...]
scaled_img1 = pygame.transform.scale(img1, (100, 100))
screen.blit(scaled_img1 , (0, 0))
pygame.display.update()