您可以用「pygame.image.frombuffer」這樣做命令。
下面是一個例子:
import picamera
import pygame
import io
# Init pygame
pygame.init()
screen = pygame.display.set_mode((0,0))
# Init camera
camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.crop = (0.0, 0.0, 1.0, 1.0)
x = (screen.get_width() - camera.resolution[0])/2
y = (screen.get_height() - camera.resolution[1])/2
# Init buffer
rgb = bytearray(camera.resolution[0] * camera.resolution[1] * 3)
# Main loop
exitFlag = True
while(exitFlag):
for event in pygame.event.get():
if(event.type is pygame.MOUSEBUTTONDOWN or
event.type is pygame.QUIT):
exitFlag = False
stream = io.BytesIO()
camera.capture(stream, use_video_port=True, format='rgb')
stream.seek(0)
stream.readinto(rgb)
stream.close()
img = pygame.image.frombuffer(rgb[0:
(camera.resolution[0] * camera.resolution[1] * 3)],
camera.resolution, 'RGB')
screen.fill(0)
if img:
screen.blit(img, (x,y))
pygame.display.update()
camera.close()
pygame.display.quit()
你見過[上Adafruit的相機教程](https://learn.adafruit.com/diy-wifi-raspberry-pi-touch-cam/overview)?這似乎有一個實時預覽與頂部的按鈕,並使用觸摸屏。 – elParaguayo
@elParaguayo是的,我已經看到了這一點,並計劃採取一些排隊 - 我只是好奇,如果任何人有任何在這個網站上的經驗。 –
拍攝...有關於此的任何更新?我有點想知道它是如何完成的。我試圖做同樣的事情,雖然沒有觸摸屏 – Chaz