Add picamera support

master
Guillaume Dott 2017-09-29 11:27:48 +02:00
parent 597d9974b1
commit 3b1967db22
2 changed files with 30 additions and 2 deletions

View File

@ -2,6 +2,8 @@
import os, sys, time, pygame
# import picamera
class Button:
def __init__(self, size, topleft):
self.up_image = pygame.image.load('button-up.png').convert_alpha()
@ -101,6 +103,31 @@ class Photo:
return self
class Camera:
def __init__(self, rect):
# self.camera = picamera.PiCamera()
# self.camera.led = False
self.rect = rect
self.img = pygame.transform.scale(pygame.image.load('tournesol.jpg'), (self.rect.width, self.rect.height))
def take(self, name):
# self.camera.capture(name + '.jpg')
print('Take picture!')
def stream(self):
return self.img
# stream = io.BytesIO()
# camera.capture(stream, use_video_port=True, format='rgb', rezise=(self.rect.width, self.rect.height))
# img = pygame.image.frombuffer(stream, (self.rect.width, self.rect.height), 'RGB')
# stream.close()
# return img
def draw_on(self, screen):
screen.blit(self.stream(), self.rect)
class Photoboite:
def __init__(self):
self.screen = self.screen()
@ -116,7 +143,8 @@ class Photoboite:
self.buttons.append(CaptureButton(button_size, topleft, self))
self.camera = pygame.Rect(20, 20, self.screen.get_width() - self.screen.get_width() / 4 - 60, self.screen.get_height() - 40)
camera_rect = pygame.Rect(20, 20, self.screen.get_width() - self.screen.get_width() / 4 - 60, self.screen.get_height() - 40)
self.camera = Camera(camera_rect)
self.font = pygame.font.Font(pygame.font.match_font('calibri'), 180)
@ -148,7 +176,7 @@ class Photoboite:
def draw(self):
self.screen.fill(self.background)
self.screen.fill((0,0,0), rect=self.camera)
self.camera.draw_on(self.screen)
for button in self.buttons:
button.draw_on(self.screen)

BIN
tournesol.jpg 100644

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB