From 9fc01aeea8a42d604e4f6bee9f07d4d4ccf2bbe4 Mon Sep 17 00:00:00 2001 From: James Hodgson Date: Fri, 7 Oct 2022 14:48:39 +0100 Subject: [PATCH] #22 Use BytesIO for camera capture --- src/picam/picam1.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/picam/picam1.py b/src/picam/picam1.py index 263778f..8c75d77 100644 --- a/src/picam/picam1.py +++ b/src/picam/picam1.py @@ -1,5 +1,6 @@ -from picam import PiCam +from src.picam import PiCam +from io import BytesIO from picamera import PiCamera class PiCam1(PiCam): @@ -36,12 +37,17 @@ class PiCam1(PiCam): def capture(self, preview: bool = False) -> bytes: # Bytes to hold output buffer out = bytes() + bytes_stream = BytesIO() if not preview: # If preview we'll already have the right resolution self.set_camera_resolution(self.capture_resolution) - self.camera.capture(out, format='rgb', use_video_port=preview) + self.camera.capture(bytes_stream, format='rgb', use_video_port=preview) + + bytes_stream.seek(0) + bytes_stream.readinto(out) + bytes_stream.close() if not preview: # If preview we'll already have the right resolution